首先描述一下需求,然后举例详细阐述。
前提:已经创建了一个返回游标的存储过程。
问题:如果获得此游标结果集中的列,注意游标结果集有多个列,而不是一个列(1列的我会)。例子如下:
返回游标的存储过程:
create or replace procedure cursorprocedure(name varchar2,mycursor out sys_refcursor) is
sqltext varchar2(100);
begin
sqltext:='select aserial from testview where id='|| name;
open mycursor for sqltext;
end cursorprocedure;调用此存储过程的SQL(游标结果集为一列的情况,这时是正常的):
declare
mycursor sys_refcursor;
content varchar2(100);
sqltext varchar2(100);
begin
cursorprocedure('1',mycursor);
loop
exit when mycursor%notfound;
fetch mycursor into content;
sqltext:=sqltext||content;
end loop;
dbms_output.put_line(sqltext);
end;结果集多列:
declare
mycursor sys_refcursor;
c mycursor%rowtype;
sqltext varchar2(100);
begin
cursorprocedure('1',mycursor);
loop
exit when mycursor%notfound;
fetch mycursor into c;
sqltext:=sqltext||c.aserial;
end loop;
dbms_output.put_line(sqltext);
其中的粗体报错"类型声明不完整"
前提:已经创建了一个返回游标的存储过程。
问题:如果获得此游标结果集中的列,注意游标结果集有多个列,而不是一个列(1列的我会)。例子如下:
返回游标的存储过程:
create or replace procedure cursorprocedure(name varchar2,mycursor out sys_refcursor) is
sqltext varchar2(100);
begin
sqltext:='select aserial from testview where id='|| name;
open mycursor for sqltext;
end cursorprocedure;调用此存储过程的SQL(游标结果集为一列的情况,这时是正常的):
declare
mycursor sys_refcursor;
content varchar2(100);
sqltext varchar2(100);
begin
cursorprocedure('1',mycursor);
loop
exit when mycursor%notfound;
fetch mycursor into content;
sqltext:=sqltext||content;
end loop;
dbms_output.put_line(sqltext);
end;结果集多列:
declare
mycursor sys_refcursor;
c mycursor%rowtype;
sqltext varchar2(100);
begin
cursorprocedure('1',mycursor);
loop
exit when mycursor%notfound;
fetch mycursor into c;
sqltext:=sqltext||c.aserial;
end loop;
dbms_output.put_line(sqltext);
其中的粗体报错"类型声明不完整"
譬如
将mycursor sys_refcursor;
替换成:
cursor mycursor is
select aserial,
field2 --需要替换成实际的字段名。
from testview;
select aserial,
field2 --需要替换成实际的字段名。
from testview; 是实现不了的