简体   繁体   中英

How to give the result of a pipelined function as a default parameter?

I have created these 4 types :

record type myrecord1 is (...)
record type myrecord2 is (...)

table tableofmyrecord1 is table of myrecord1;
table tableofmyrecord2 is table of myrecord2;

and 2 functions :

function  a(k in tableofmyrecord2) return packageName.tableofmyrecord1 PIPELINED;
function  b return packageName.tableofmyrecord2  PIPELINED;

I can effectively give a default parameter ; null, the table empty, a table that I have create, but I can give directly the result of a of pipelined function.

function  a return packageName.tOfmyrecord(k in tableofmyrecord2 :=package.b)   PIPELINED

This does'nt work.

This solution does'nt work too.

declare
    defaultArgOFA :=package.b;
    function  a return packageName.tOfmyrecord(k in tableofmyrecord2 :=defaultArgOFA)  PIPELINED

same error

PLS-00653: aggregate/table functions are not allowed

This error says that you cannot call pipelined functions using PLSQL, so you can't directly write v:=a() . But you can use SQL. Below is an example where pipelined b gets input from pipelined a and multiplies salaries.

Package:

create or replace package pkg is
  type tr is record (id int, name varchar2(10), sal int);
  type tt is table of tr;
  function a return tt pipelined;
  function b(par in tt) return tt pipelined;
end pkg;

Body:

create or replace package body pkg is

function a return tt pipelined is
  v_tr tr;
begin
  v_tr.id := 1;  v_tr.name := 'Mark';  v_tr.sal := 100;
  pipe row (v_tr);

  v_tr.id := 2;  v_tr.name := 'Pete';  v_tr.sal := 120;
  pipe row (v_tr);
  return;
end;

function b(par in tt) return tt pipelined is
  v_tr tr;
begin
  for i in 1..par.last loop
    v_tr := par(i);
    v_tr.sal := v_tr.sal * 10;
    pipe row (v_tr);
  end loop;
  return;
end;

end pkg;

And this test worked for me:

select * from table(pkg.b(pkg.a));

Result:

    ID NAME              SAL
------ ---------- ----------
     1 Mark             1000
     2 Pete             1200

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM