簡體   English   中英

如何將流水線函數的結果作為默認參數?

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

我創建了這 4 種類型:

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

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

和2個功能:

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

我可以有效地給出一個默認參數; null,表為空,我創建的表,但我可以直接給出流水線函數的結果。

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

這不起作用。

此解決方案也不起作用。

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

同樣的錯誤

PLS-00653: 不允許聚合/表函數

此錯誤表示您無法使用 PLSQL 調用流水線函數,因此您無法直接編寫v:=a() 但是您可以使用 SQL。 下面是其中流水線的示例b從流水線獲取輸入a和乘法薪水。

包裹:

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;

身體:

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;

這個測試對我有用:

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

結果:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM