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:
declarecur sys_refcursor;beginopen cur for select 'a' s, 1 n from dual;close cur;open cur for select 9 n from dual; --跟上面的游标类型不一致close cur;end;/
ORACLE SYS_REFCURSOR VS REF CURSOR
没有评论:
发表评论