ref游标(动态游标)

 

参照变量--用于存放数值指针的变量

 

   游标变量(ref cursor)

 

  使用游标时,当定义游标时不需要指定相应的select语句,但是当使用

 

   游标时(open时)需要指定select语句,这样一个游标就与一个select语句结合了。

 

游标实例:

 

1.请使用pl/sql编写一个块,可以输入部门号,并显示该部门所有员工姓名和他的工资。

 

2.1的基础上,如果某个员工的工资低于200元,就添加100元。

 

declare

 

--定义游标类型

 

typesp_emp_copy_cursor is ref cursor;

 

--定义一个游标变量

 

test_cursor sp_emp_copy_cursor;

 

v_ename emp_copy.ename%type;

 

v_sal emp_copy.sal%type;

 

begin

 

  --test_cursor和一个select结合

 

  opentest_cursor for select ename,sal from emp_copy wheredeptno=&no;

 

  --循环取出(fethch)

 

  loop

 

    fetch test_cursor into v_ename,v_sal;

 

    --判断是否test_cursor是否为空

 

    exit when test_cursor%notfound;

 

    dbms_output.put_line('名字:'||v_ename||'工资:'||v_sal);

 

  end loop;

 

  --关闭游标

 

  closetest_cursor;

 

end;

 

 


来自:http://blog.sina.com.cn/s/blog_62e75cd001015mkr.html

posted @ 2014-08-05 14:35  apem  阅读(734)  评论(0编辑  收藏  举报