oracle的游标

--声明包的游标变量
create or replace package cmspackage is

type my_cursor is ref cursor; 

end cmspackage;
--运用
declare  
v_tot_salary emp.sal%type;
v_sql varchar2(59);
v_deptno emp.deptno%type;
v_dname dept.dname%type;
cms_cursor cmspackage.my_cursor;   
begin
v_sql:='select deptno,dname from dept order by deptno';
open cms_cursor for v_sql;
loop
fetch cms_cursor into v_deptno,v_dname;
IF cms_cursor%NOTFOUND THEN
EXIT;
end if; 
dbms_output.put_line('department:'|| v_deptno||'-'||v_dname);
end loop;  
/*
  for r_dept in cms_cursor loop  
     dbms_output.put_line('department:'|| r_dept.deptno||'-'||r_dept.dname);  
     v_tot_salary:=0;  
     for r_emp in (select ename,sal from emp where deptno=r_dept.deptno order by ename) loop  
       dbms_output.put_line('name:'|| r_emp.ename ||' salary:' ||r_emp.sal);  
       v_tot_salary:=v_tot_salary+r_emp.sal;  
     end loop;  
  dbms_output.put_line('toltal salary for dept:'|| v_tot_salary);  
  end loop;*/
  close cms_cursor;  
end;  

 

  execute immediate vql  into cms_cursor;

 

你可能感兴趣的:(oracle)