Oracle PLSQL Demo

declare

    Type ref_cur_variable IS REF cursor;
    cur_variable ref_cur_variable;
    
    v_ename varchar2(10);
    v_deptno number(2);
    v_sal number(7,2);

    v_sql varchar2(100) := 'select t.ename, t.deptno, t.sal from scott.emp t';

begin

    Open cur_variable For v_sql;
    
    Loop
        fetch cur_variable
            InTo v_ename, v_deptno, v_sal;
        Exit When cur_variable%NotFound;
        dbms_output.put_line(cur_variable%rowcount || ' -> ' || v_ename ||
                             '   ' || v_deptno || '   ' || v_sal);
    End Loop;
    Close cur_variable;

end;
原文地址:https://www.cnblogs.com/nick-huang/p/4609116.html