游标的使用

来源:互联网 发布:java html 转换为xml 编辑:程序博客网 时间:2024/05/11 02:24
--创建包,并且定义类型test_cursor为游标
create or replace package testpackage
       as type test_cursor is ref cursor;
end testpackage;

--创建过程,获取数据
create or replace procedure afei_pro_emp(
       spNo in number,
       spcursor out testpackage.test_cursor) is
begin
       open spcursor for
            select * from emp where deptno = spNo;
end afei_pro_emp;

select * from emp;



declare
--定义一个游标
type afei_cur_test1 is ref cursor;
--定义一个游标变量
test_cur afei_cur_test1;
--定义变量
v_name emp.empname%type;
v_sal emp.wage%type;
begin
--执行部分
--把test_cur和一个select结合起来
open test_cur for select empname, wage from emp where postcode = &no;
--循环取出
loop
     fetch test_cur into v_name, v_sal;
     --判断是否test_cur为空
     exit when test_cur % notfound;
     dbms_output.put_line('姓名:' || v_name || ' 工资:' || v_sal);
end loop;
end;
0 0
原创粉丝点击