Error when calling a function that returns a pipeline from another function [message #607935] |
Thu, 13 February 2014 10:18 |
ora1980
Messages: 251 Registered: May 2008
|
Senior Member |
|
|
How do I successfully call a function which returns a pipelined function from another function ?
-- my_data is a function that returns pipelined function
FUNCTION my_data(rec IN OUT emp.employees%ROWTYPE
)
RETURN out_rows PIPELINED IS
BEGIN
---- logic to populate
PIPE ROW (record_type);
RETURN;
EXCEPTION
WHEN OTHERS THEN
null
END my_data;
-- Below function should call the above one.
FUNCTION function_2(rec IN OUT emp.employees%ROWTYPE
) RETURN out_rows PIPELINED
IS
final_rows_v out_rows ;
BEGIN
select res.* BULK COLLECT INTO final_rows_v
FROM TABLE(my_data(rec)) res;
FOR i in 1..final_rows_v .COUNT LOOP
PIPE ROW(final_rows_v (i));
END LOOP;
return;
END function_2;
I am getting
PLS-00382: expression is of wrong type
PLS-00306: wrong number or types of arguments in call to my_data
|
|
|
|
Re: Error when calling a function that returns a pipeline from another function [message #607944 is a reply to message #607935] |
Thu, 13 February 2014 13:49 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
Pipelined function can only be called from SQL statement. In order for a user defined function to be callable from SQL statement it must (among other things) not have OUT/IN OUT parameters - only IN parameters:
SCOTT@orcl > desc NumList
NumList TABLE OF NUMBER
SCOTT@orcl > create or replace
2 function f1(p_deptno in number)
3 return NumList
4 pipelined
5 is
6 begin
7 for v_rec in (select sal from emp where deptno = p_deptno) loop
8 pipe row(v_rec.sal);
9 end loop;
10 end;
11 /
Function created.
SCOTT@orcl > select * from table(f1(10));
COLUMN_VALUE
------------
2450
5000
1300
SCOTT@orcl > create or replace
2 function f1(p_deptno in out number)
3 return NumList
4 pipelined
5 is
6 begin
7 for v_rec in (select sal from emp where deptno = p_deptno) loop
8 pipe row(v_rec.sal);
9 end loop;
10 end;
11 /
Function created.
SCOTT@orcl > select * from table(f1(10));
select * from table(f1(10))
*
ERROR at line 1:
ORA-06572: Function F1 has out arguments
SCOTT@orcl >
As you can see your issues start with first pipelined function my_data.
SY.
|
|
|