ref cursor与oracle中的cursor有何不同

ref cursor与oracle中的cursor有何不同,oracle,Oracle,我有一个plsql块,在那里我使用了许多游标。但我的前辈建议我使用ref cursor。据我所知,ref游标将消耗大量内存。请您提出建议,使用ref游标代替游标是一种好的做法。普通的plsql游标在定义上是静态的 Ref游标可以动态打开,也可以基于逻辑打开 Declare type rc is ref cursor; cursor c is select * from dual; l_cursor rc; begin if ( to_char(sysdate,'dd') = 30 ) the

我有一个plsql块,在那里我使用了许多游标。但我的前辈建议我使用ref cursor。据我所知,ref游标将消耗大量内存。请您提出建议,使用ref游标代替游标是一种好的做法。

普通的plsql游标在定义上是静态的

Ref游标可以动态打开,也可以基于逻辑打开

Declare
type rc is ref cursor;

cursor c is select * from dual;

l_cursor rc;
begin
if ( to_char(sysdate,'dd') = 30 ) then
open l_cursor for 'select * from emp';
elsif ( to_char(sysdate,'dd') = 29 ) then
open l_cursor for select * from dept;
else
open l_cursor for select * from dual;
end if;
open c;
end;
/
无论您运行该块游标多少次,C都将始终保持不变 从双重选择中选择*。ref游标可以是任何东西

另一个区别是ref游标可以返回给客户机。A. 无法将plsql游标返回到客户端

另一个区别是游标可以是全局的-ref游标不能 不能在过程/函数之外定义它们

另一个不同之处是ref游标可以从子例程传递到 子例程-不能使用光标


这个问题似乎没有道理。ref游标是一个游标。现在还不清楚到底建议了什么——举个例子会很有用。如果您有一段代码使用了大量游标,我的第一个想法是您没有编写基于集合的逻辑,这将大大提高效率。