oracle-存储过程实例


<span style="font-size:18px;color:#FF0000;">--定义一个存储过程,获取给定部门工资总和,(通过out参数)要求:部门号和工资总额定义为参数</span>
 create or replace produre get_sal2(dept_id number,sumsal out number)
is
 cursor salarya is select salary from employees where department_id=dept_id;
 begin
 sumsal:=0;
 for c in salarya loop
 sumsal :=sumsal+c.salary;
 end loop;
 dbms_output.put_line(sumsal);
 end; 

//调用

declare

v_sal number(10):=0;

begin

get_sal2(80,v_sal);

end;



create or replace procedure add_sal(dept_id number,temp_sal out number)

is
cursor sal_cursor is select employee_id,salary,hire_date from employee where
 department_id=dept_id;
 
  v_i number(4,2):=0;
 
  begin
  temp_sal:=0;
   for c in sal_cursor loop
    if to_char(c.hire_date,'yyyy')<'1995' then v_i:=0.05;
    elsif to_char(c.hire_date,'yyyy')<'1998' then v_i:=0.03;
    else v_i:=0.01;
    end if;
    --1.更新工资
    update employees set salary=salay*(1+v_i) where employee_id=c.employee_id;
    
    --2.付出的成本
    
    temp_sal:=temp_sal+c.salay*v_i;
    end loop;
    end;

//调用

declare v_temp number(10):=0;

begin

  add_sal(80,v_temp);

end;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值