选择时出现Oracle存储过程错误

选择时出现Oracle存储过程错误

本文介绍了选择时出现Oracle存储过程错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了

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

在oracle中执行select命令存储过程时出错.我的程序是

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

推荐答案

您没有正确调用该过程.

You are not calling the procedure properly.

SQL * Plus 中,您可以按照以下步骤进行操作:

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>

或者,

可以在 PL/SQL 中将其引用为:

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>

这篇关于选择时出现Oracle存储过程错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 20:41