3

我有一个带有 2 个流水线功能的包。当我试图用另一个函数作为参数调用一个函数时,我收到“ORA-06553:PLS-306:调用中的参数数量或类型错误”错误。

这是包:

create or replace NONEDITIONABLE TYPE RESULTING_RECORD_RT as object
   (
          CALENDAR  NVARCHAR2(1024), 
          PRODUCT   NVARCHAR2(1024), 
          MEASURE   NVARCHAR2(1024), 
          VALUE     NUMBER
   );
/
create or replace NONEDITIONABLE TYPE RESULTING_COLS_RT IS TABLE OF RESULTING_RECORD_RT;
/
create or replace package pipe_pkg as
function pipe_func_emp return RESULTING_COLS_RT PIPELINED;
function pipe_func_emp2(input_Set IN resulting_cols_rt) return RESULTING_COLS_RT PIPELINED;
end;
/
create or replace package body pipe_pkg as
function pipe_func_emp return RESULTING_COLS_RT
PIPELINED
is
    test_tbl resulting_cols_rt:= resulting_cols_rt();
begin
    test_tbl.extend;
    test_tbl(1):=resulting_record_rt('A','B','C',1);
    test_tbl.extend;
    test_tbl(2):=resulting_record_rt('A','B','D',2);
    PIPE ROW(test_tbl(1));
    PIPE ROW(test_tbl(2));
    return;
end;
function pipe_func_emp2(input_Set IN resulting_cols_rt) return RESULTING_COLS_RT
PIPELINED
is
    v_tmp NVARCHAR2(10240);
    l_res SYS_REFCURSOR;
    recs resulting_record_rt;
begin
    open l_res for select * from table(input_Set);
    loop
        fetch l_res into recs;
        PIPE ROW(recs);
        exit when l_res%notfound;
    end loop;
    close l_res;
    return;
end;
end;
/

我调用函数如下:

select * from TABLE(pipe_pkg.pipe_func_emp2(CURSOR(select * from TABLE(pipe_pkg.pipe_func_emp()))));

并且调用抛出错误:

ORA-06553: PLS-306: wrong number or types of arguments in call to 'PIPE_FUNC_EMP2'
06553. 00000 -  "PLS-%s: %s"

我究竟做错了什么?

4

1 回答 1

4

该函数pipe_func_emp2期望RESULTING_COLS_RT作为它的参数,但得到REF CURSOR. 这些是不兼容的类型。

尝试以下流水线函数链接的可重现示例:

create or replace type somerow  as object (id int, val varchar2 (8))
/
create or replace type sometab is table of somerow
/
create or replace package pack as
    function func1 return sometab pipelined;
    function func2 (cur sys_refcursor) return sometab pipelined;
end;
/
create or replace package body pack as
    function func1 return sometab pipelined is
        tab sometab := sometab (somerow (1,'AAA'), somerow (2,'BBB'));
    begin
        for i in 1..tab.count loop 
            pipe row (tab(i)); 
        end loop;
        return;
    end;
    function func2 (cur sys_refcursor) return sometab pipelined is
        sr somerow;
    begin
        loop
            fetch cur into sr;
            exit when cur%notfound;
            pipe row (sr);
        end loop;
        close cur;
        return;
    end;
end;
/

查询及其结果:

select * 
from table (pack.func2 (
    cursor (select value (p) from table (pack.func1()) p )))
/

        ID VAL     
---------- --------
         1 AAA     
         2 BBB     
于 2021-05-04T17:46:15.760 回答