ORACLE SYS_REFCURSOR VS REF CURSOR

CURSOR是强类型,SYS_REFCURSOR 是弱类型(类似C#的var)。

Cursor:

ORACLE SYS_REFCURSOR VS REF 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

ORACLE SYS_REFCURSOR VS REF CURSOR

 

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;
/

ORACLE SYS_REFCURSOR VS REF CURSOR

 

ORACLE SYS_REFCURSOR VS REF CURSOR

上一篇:mysql 超时配置


下一篇:MySQL备份,使用xtrabackup备份全实例数据时,会造成锁等待吗?那么如果使用mysqldump进行备份呢?