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 on
declare
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;
/