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 p ...
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; /View Code
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; /