我在用甲骨文10g。我在存储过程中有一个查询,它从表中选择整行。当前,它返回强类型的ref游标(tablename%rowtype)。现在我必须向这个查询添加一些动态WHERE子句,但是dynamic不支持强引用游标。以前也有人这样问过。我的问题是:有解决办法吗?使用某种包装器、转换或DBMS魔术将弱游标转换为强游标?我可以保证结果与表行类型匹配。
发布于 2014-02-19 21:04:29
可能有更好的方法来实现您的基本目标,但是如果您真的希望将动态SQL中的值转换为强类型的反射游标,我想您可以这样做:
create table TESTTABLE(TESTID number not null);
create global temporary table TEMPTESTTABEL(TESTID number not null);
create or replace procedure testprocedure is
type testtablerefcursor is ref cursor return TESTTABLE%rowtype;
type testtabletable is table of TESTTABLE%rowtype;
mycursor testtablerefcursor;
mysyscursor SYS_REFCURSOR;
mytesttable testtabletable;
begin
open mysyscursor for 'select * from TESTTABLE';
fetch mysyscursor bulk collect into mytesttable;
close mysyscursor;
forall i in mytesttable.first..mytesttable.last
insert into TEMPTESTTABEL values mytesttable(i);
open mycursor for select testid from TEMPTESTTABEL;
end;
/https://dba.stackexchange.com/questions/59149
复制相似问题