PLSQL_游标变量

来源:互联网 发布:c51和c语言的区别 编辑:程序博客网 时间:2024/05/22 14:37

 declare
 --声明一个游标类型
 type mycur is ref cursor;
 --声明一个游标变量,将类型实例化
 cur mycur;
 v_name emp.ename%type;
 v_job  emp.job%type; 
 begin
   select job into v_job from emp where empno='111';
   if v_job = 'saler' then
     --为游标指定一个结果集
     open cur for select ename from emp where sal<3000;
   else
     --为游标指定一个结果集
     open cur for select ename from emp where sal>3000;
   end if;
   --提取
   while cur%found loop
     dbms_output.put_line(v_name);
     fetchcur into v_name;
   end loop; 
   --关闭
   close cur;
 exception
   when others then
     dbms_output.put_line(sqlcode||sqlerrm);
 end;