当前位置: 代码迷 >> Oracle管理 >> ORACLE中如何显示一个过程中的游标值
  详细解决方案

ORACLE中如何显示一个过程中的游标值

热度:6   发布时间:2016-04-24 05:05:09.0
ORACLE中怎么显示一个过程中的游标值
[code=SQL][/code]
create table s(swmc varchar2(2000),swbm varchar2(9));

insert into s values('abcdef','213050001');
insert into s values('qwerty','213050002');
insert into s values('zxcvbn','213050003');

create table o(login_name varchar2(10),swbm varchar2(9));

insert into o values('zhangsan','213050001');
insert into o values('lisi','213050002');
insert into o values('lisi','213050003');

commit;

create or replace package testpkg1 as
type c_cur is ref cursor;
end;

create or replace procedure get_swmc(v_login_name in varchar2,c_swmc out testpkg1.c_cur) is
begin
open c_swmc for select swmc from s where exists (select 1 from o where s.swbm=o.swbm and o.login_name=v_login_name);
end;

然后问:我怎么把c_swmc游标里的值打出来?输出的样子如下:
SWMC  
---------- 
qwerty  
zxcvbn  
本人菜鸟,想学sql,谢谢各位!

------解决方案--------------------
SQL code
set serveroutput ondeclare     v_login_name varchar2(10):='lisi';    rec s.swmc%type;    cur testpkg1.c_cur;begin    get_swmc(v_login_name,cur);    dbms_output.put_line('SWMC ');    dbms_output.put_line('--------- ');    loop            fetch cur into rec;        exit when cur%notfound;        dbms_output.put_line(rec);    end loop;end;/
  相关解决方案