【无标题】


declare
begin
  loop
    dbms_output.put_line(' ');
    dbms_output.put_line(' ');
    exit when 1=1;
  end loop;
  dbms_output.put_line('3'); 
end;  
```sql
declare
begin
  for i in 1..10 loop
    if i = 6 then
      continue;
    end if;
    dbms_output.put_line('数字是'||i);
  end loop;
end; 
``sql
create or replace procedure p1
is
begin
  dbms_output.put_line('网络错误,请找移动');
end; 

--2、写一个存储过程,传入一个部门编号,
--输出该部门员工的工资、奖金、总收入。
create or replace procedure p1( dno emp.deptno%type;)
is
  v3 number;
begin
  for row in(
    select * from emp e where e.deptno=dno) loop
    v3 := row.sal+nvl(row.comm,0);
    dbms_output.put_line('部门编号'||dno ||'员工工资'||row.sal 
    || '奖金'||nvl(row.comm,0)||'总收入'||v3);
  end loop;
end;   

--3、写一个存储过程,传入一个部门编号,
--给emp表中该部门的每个员工增加100元奖金,并显示这些员工的奖金 。
create or replace procedure p2( dno emp.deptno%type;)
is  
  v_comm emp.comm%type;
begin
  for row in (select * from emp e where e.deptno=dno)loop
    v_comm := nvl(row.comm,0)+100;
    dbms_output.put_line('员工奖金'||v_comm);
  end loop;
end; 

begin
  update emp set sal = sal + 1;
  if sql%found then
    dbms_output.put_line('工资修改成功,影响行数'|| sql%rowcount);
  else
    dbms_output.put_line('没有修改');
  end if;
end;
    
  select * from emp;

--1、创建一个通过雇员编号获取部门经理编号的函数
create or replace function f1(eno number) return number 
is 
  v1 number;
begin
  select e.mgr into v1 from emp e where eno=e.empno;
  return v1;
end;
select f1(7369) from dual;

--3、写一个函数,输入员工编号,得到部门的平均工资。
create or replace function f3(no int) return int is
  v1 int;
begin
  select avg(sal) into  v1 from emp where deptno=(select deptno from emp where empno=no);
  return v1;
end;

--4、写一个函数,根据员工号,获得员工到目前为止参加工作年限,
--员工号不存在时返回“此员工号不存在”。提示:函数的返回类型是varchar2。
create or replace function f2(eno number) return varchar2
is
  v1 varchar2(32);
  v2 number;
begin
  select count(1) into v2 from emp e where e.empno=eno;
  if v2=0 then
    return '不存在';
    end if;
  select floor(to_char((sysdate-e.hiredate))/365) 
  into v1
  from emp e where e.empno=eno;
  return v1;
end;
  
 



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值