当前位置: 代码迷 >> Oracle管理 >> 在存储过程中加入对薪资的从小到大排序,和求和
  详细解决方案

在存储过程中加入对薪资的从小到大排序,和求和

热度:262   发布时间:2016-04-24 04:05:37.0
在存储过程中加入对工资的从小到大排序,和求和

create table payroll(emp_no number(10) primary key,emp_date date,emp_salary decimal(10,2));
insert into payroll values(102041,to_date('2008-6-5','yyyy-mm-dd'),6000);
insert into payroll values(102042,to_date('2009-3-2','yyyy-mm-dd'),7000);
insert into payroll values(102043,to_date('2008-6-3','yyyy-mm-dd'),5000);
存储过程
create or replace procedure pro_payroll4(rnt int)is
 f_no char(20);
 f_date date;
 count_1 number:=0;
 count_2 number:=0;
 cursor cur_1  is select emp_no,emp_date from payroll;
 begin
 open cur_1;
 loop
 fetch cur_1 into f_no,f_date;
 exit when cur_1%notfound;
 if to_char(sysdate,'yyyy') - to_char(f_date,'yyyy')=5 then
    update payroll set emp_salary=emp_salary*1.05 where
           emp_no=f_no;
    elsif to_char(sysdate,'yyyy') - to_char(f_date,'yyyy')=6 then
    update payroll set emp_salary=emp_salary*1.06 where
           emp_no=f_no;
    elsif to_char(sysdate,'yyyy') -  to_char(f_date,'yyyy')=7 then
    update payroll set emp_salary=emp_salary*1.07 where
           emp_no=f_no;
    end if;
    commit;
    end loop;
    close cur_1;   
end;
要在存储过程中加入对工资的从小到大排序,和求和
------解决思路----------------------

-- 是这个意思吗?
SQL> create or replace procedure show_data
  2  as
  3  begin
  4  for x in (
  5  select to_char(emp_no) emp_no , emp_salary from payroll
  6  union all
  7  select '总计' , sum(emp_salary) from payroll
  8  order by 2
  9  ) loop
 10  dbms_output.put_line('name:' 
------解决思路----------------------
 x.emp_no 
------解决思路----------------------
 '  salary:' 
------解决思路----------------------
 x.emp_salary);
 11  end loop ;
 12  end ;
 13  /

过程已创建。

SQL>
SQL> call show_data();
name:102043  salary:5000
name:102041  salary:6000
name:102042  salary:7000
name:总计  salary:18000

调用完成。

SQL>
SQL> drop procedure show_data;

过程已删除。

SQL>