Oracle stored procedure error on select

人走茶凉 提交于 2019-12-24 06:39:08

问题


I am getting

ORA-06550: line 2, column 1:
PLS-00306: wrong number or types of arguments in call to 'GET_EMP_RS'
ORA-06550: line 2, column 1:
PL/SQL: Statement ignored

Error while executing select command stored procedure in oracle. My Procedure is

CREATE OR REPLACE
PROCEDURE get_emp_rs (p_deptno    IN  emp.EMPNO%TYPE,
                      p_recordset OUT SYS_REFCURSOR) AS 
BEGIN 
  OPEN p_recordset FOR
    SELECT ENAME,
           JOB,
           MGR
    FROM   emp
    WHERE  EMPNO = p_deptno
    ORDER BY ENAME;
END;
/

回答1:


You are not calling the procedure properly.

In SQL*Plus, you could do it as:

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>

Or,

It can be referenced from PL/SQL as:

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>


来源:https://stackoverflow.com/questions/28803316/oracle-stored-procedure-error-on-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!