您的位置:首页 > 数据库

pl/sql 游标变量实例

2013-10-16 20:52 260 查看
参照变量-ref cursor游标变量。

使用游标时,当定义游标时不需要指定相应的select语句,但是当使用游标时(open时)需要指定select语句,这样一个游标与一个select语句结合了。实例如下:

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

declare

--定义游标类型 sp_emp_cursor

type sp_emp_cursor is ref cursor;

--定义一个游标变量

test_cursor sp_emp_cursor;

--定义变量

v_ename emp.ename%type;

v_sal emp.sal%type;

begin

--执行

--把test_cursor和一个select结合

open test_cursor for select ename,sal from emp where deptno=&no;

--循环取出

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;

end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: