Oracle 动态sql 打开 sys_refcursor 游标类型


declare
    v_sql varchar2(2000);
    --type cur_type is ref sys_refcursor; --PLS-00103: Encountered the symbol "SYS_REFCURSOR" when expecting one of the following: cursor
    --v_out cur_type;
    v_out sys_refcursor;
    --v_row v_out%rowtype;    --PLS-00320: the declaration of the type of this expression is incomplete or malformed
    v_row emp%rowtype;
begin
    v_sql := 'select * from emp where empno <= :1';
    open v_out for v_sql using 7799;
    loop
        exit when v_out%notfound;
        fetch v_out into v_row;
        dbms_output.put_line(v_row.empno || ':' || v_row.ename); 
    end loop;
    close v_out;
    
    dbms_output.put_line('#########################################');
    
    v_sql := 'select * from emp where empno <= :1';
    open v_out for v_sql using 7698;
    loop
        exit when v_out%notfound;
        fetch v_out into v_row;
        dbms_output.put_line(v_row.empno || ':' || v_row.ename); 
    end loop;
    close v_out;
end;

 

 

参考:https://blog.csdn.net/zhangzeyuaaa/article/details/53505163

你可能感兴趣的:(PL/SQL,Oracle,存储过程,sys_refcursor,游标,Oracle,动态sql)