Oracle存储过程:返回多行

时间:2014-07-10 09:54:28

标签: sql oracle stored-procedures plsql procedure

请您帮我保存我的存储过程? 我希望它获取输入并将多行返回给前端应用程序。 但是我的存储过程中有错误。

对象类型:

CREATE TYPE org_rspnsble_prsns_type 
    AS OBJECT (
    "appId" varchar2, 
    "orgId" varchar2, 
    "domainId" varchar2, 
    "leadName" varchar2, 
    "personId" number
);

表格类型:

CREATE TYPE org_rspnsble_prsns_table 
AS TABLE OF org_rspnsble_prsns_type;

存储过程:

CREATE OR REPLACE PROCEDURE GetNames( appIdInput IN varchar2, orgIdInput IN varchar2, p_arr OUT org_rspnsble_prsns_table )
AS
BEGIN
    SELECT "appId", "orgId", "domainId", "leadName", "personId"
    BULK COLLECT INTO p_arr
    FROM (
        select "appId", "orgId", "domainId", "leadName", "personId"
        from tableA
    UNION
        select "appId", "orgId", "domainId", "leadName", "personId"
        from tableB
    )
    WHERE "appId" = appIdInput
    AND "orgId" = orgIdInput;
END;

存储过程中的错误是:

  • 忽略SQL语句
  • 没有足够的价值

非常感谢你。

2 个答案:

答案 0 :(得分:2)

我找到了一个很好的方法: https://asktom.oracle.com/pls/apex/ASKTOM.download_file?p_file=6551171813078805685

create or replace package types 
as 
    type cursorType is ref cursor; 
end; 
/
create or replace function sp_ListEmp return types.cursortype 
as 
    l_cursor    types.cursorType; 
begin 
    open l_cursor for select ename, empno from emp order by ename;
    return l_cursor; 
end; 
/
create or replace procedure getemps( p_cursor in out types.cursorType )
as
begin
open p_cursor for select ename, empno from emp order by ename;
end;
/

感谢所有回答的人。

答案 1 :(得分:1)

您的SELECT选择5列为1个变量。你必须要么 A)在您的选择中创建对象:

SELECT org_rspnsble_prsns_type("appId", "orgId", "domainId", "leadName", "personId")
BULK COLLECT INTO p_arr
...

或B)将类型创建为记录:

CREATE TYPE org_rspnsble_prsns_type 
AS RECORD (...