Oracle Ref游标和out参数

时间:2012-08-12 08:53:50

标签: stored-procedures plsql oracle11g ref-cursor

我要求将IN OUT参数与引用游标一起作为存储过程的返回。目前我正在关注。

create table dept
( dept_id number,
  name varchar2(40),
  location varchar2(200)
);

CREATE OR REPLACE PACKAGE HR.SP_PACKAGE AS 

  TYPE dept_type IS REF CURSOR RETURN HR.dept%ROWTYPE;

END SP_PACKAGE;

CREATE OR REPLACE PROCEDURE HR.MIXED_IN_INOUT_REF_PARAM 
(
  P_ID IN NUMBER  
, P_NAME_TO_LOCATION IN OUT VARCHAR2  
, P_RCURSOR OUT SP_PACKAGE.dept_type
) AS 
BEGIN
  SELECT name INTO P_NAME_TO_LOCATION FROM HR.dept WHERE dept_id = p_id AND name =  P_NAME_TO_LOCATION;
  OPEN P_RCURSOR FOR
      select *
      from HR.dept;
END MIXED_IN_INOUT_REF_PARAM;

即使编译成功,我也会在运行时遇到一些错误。

ORA-06550: line 4, column 17:
PLS-00201: identifier 'CURSOR' must be declared
ORA-06550: line 4, column 13:
PL/SQL: Item ignored
ORA-06550: line 12, column 18:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 9, column 3:
PL/SQL: Statement ignored
ORA-06550: line 21, column 17:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 21, column 3:
PL/SQL: Statement ignored

我正在使用Sql Developer。任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:0)

这样改变 删除回报

CREATE OR REPLACE PACKAGE HR.SP_PACKAGE AS 

  TYPE dept_type IS REF CURSOR ;

END SP_PACKAGE;

你可以让它更像这样的动态想法

open p_cursor FOR  'SELECT *  FROM DEPT where ' ||  V_WHERE;

答案 1 :(得分:0)

你的proc chamibuddhika没有问题,我认为你如何调用它有一些问题。我尝试创建相同的程序,它可以正常运行你的程序,如下所示:

declare
v_temp varchar2(200):='ACCOUNTING';
rec SP_PACKAGE.dept_type;
v_rec rec%ROWTYPE;

begin
MIXED_IN_INOUT_REF_PARAM(10,v_temp,rec);

LOOP
FETCH rec INTO v_rec;
EXIT WHEN rec%NOTFOUND;
 dbms_output.put_line(v_rec.name);

END LOOP;

end;

<强>输出

 ACCOUNTING
 RESEARCH
 SALES
 OPERATIONS

你的proc有一个问题,当proc中的查询没有返回任何内容时,它会给你no_data_found例外。所以你需要在你的proc中处理它。