ORACLE SYS_REFCURSOR VS REF CURSOR
CURSOR是强类型,SYS_REFCURSOR 是弱类型(类似C#的var)。
Cursor:
create or replace package pkg as cursor cur is select 1 n from dual; type tcur is ref cursor return pkg.cur%rowtype; end pkg; / --类型报错 declare cur pkg.tcur; begin open cur for select 'a' s, 1 n from dual; --跟游标定义的类型不一致 end; / --正常运行 declare cur pkg.tcur; begin open cur for select 'kkk' n from dual; end; / --正常运行 declare cur pkg.tcur; begin open cur for select 900 n from dual; end; /
Sys_refcursor:
declare cur sys_refcursor; begin open cur for select 'a' s, 1 n from dual; close cur; open cur for select 9 n from dual; --跟上面的游标类型不一致 close cur; end; /
量变会引起质变。