Oracle
 sql >> Database >  >> RDS >> Oracle

Errore di procedura memorizzata Oracle su select

Non stai chiamando la procedura correttamente.

In SQL*Plus , potresti farlo come:

SQL> CREATE OR REPLACE
  2  PROCEDURE get_emp_rs(
  3      p_deptno IN emp.DEPTNO%TYPE,
  4      p_recordset OUT SYS_REFCURSOR)
  5  AS
  6  BEGIN
  7    OPEN p_recordset FOR
  8    SELECT ENAME, JOB, MGR
  9       FROM emp
 10     WHERE DEPTNO = p_deptno
 11    ORDER BY ENAME;
 12  END;
 13  /

Procedure created.

SQL>
SQL> SHOW ERRORS
No errors.
SQL>
SQL> variable cur refcursor
SQL>
SQL> DECLARE
  2  cur SYS_REFCURSOR;
  3  BEGIN
  4     get_emp_rs(10, :cur);
  5  END;
  6  /

PL/SQL procedure successfully completed.

SQL>
SQL> print cur;

ENAME      JOB              MGR
---------- --------- ----------
CLARK      MANAGER         7839
KING       PRESIDENT
MILLER     CLERK           7782

SQL>

Oppure,

Può essere referenziato da PL/SQL come:

SQL> DECLARE
  2    l_cursor SYS_REFCURSOR;
  3    l_ename   emp.ename%TYPE;
  4    l_job     emp.job%TYPE;
  5    l_mgr     emp.mgr%TYPE;
  6  BEGIN
  7    get_emp_rs (p_deptno => 10, p_recordset => l_cursor);
  8    LOOP
  9      FETCH l_cursor INTO l_ename, l_job, l_mgr;
 10      EXIT
 11    WHEN l_cursor%NOTFOUND;
 12      DBMS_OUTPUT.PUT_LINE(l_ename || ' | ' || l_job || ' | ' || l_mgr);
 13    END LOOP;
 14    CLOSE l_cursor;
 15  END;
 16  /
CLARK | MANAGER | 7839
KING | PRESIDENT |
MILLER | CLERK | 7782

PL/SQL procedure successfully completed.

SQL>