gpt4 book ai didi

oracle - 流水线函数调用另一个流水线函数

转载 作者:行者123 更新时间:2023-12-04 04:14:07 25 4
gpt4 key购买 nike

这是一个包含两个流水线函数的包:

create or replace type tq84_line as table of varchar2(25);
/

create or replace package tq84_pipelined as

function more_rows return tq84_line pipelined;
function go return tq84_line pipelined;

end tq84_pipelined;
/

Ant对应的包体:
create or replace package body tq84_pipelined as

function more_rows return tq84_line pipelined is
begin

pipe row('ist');
pipe row('Eugen,');

return;

end more_rows;

function go return tq84_line pipelined is
begin

pipe row('Mein');
pipe row('Name');

/* start */
for next in (
select column_value line from table(more_rows)
)
loop
pipe row(next.line);
end loop;
/* end */

pipe row('ich');
pipe row('weiss');
pipe row('von');
pipe row('nichts.');

end go;

end tq84_pipelined;
/

重要的是 go 类型的调用 more_rowsfor next in ... /* start */之间和 /* end */
我可以按如下方式使用该软件包:
select * from table(tq84_pipelined.go);

这一切都很好,但我希望我可以替换 /* start */ 之间的行和 /* end */只需调用 more_rows .

但是,这显然是不可能的,因为它会生成 PLS-00221:“MORE_ROWS”不是过程或未定义 .

所以,我的问题是:真的没有办法缩短循环吗?

编辑

显然,从到目前为止的答案来看,我的问题并不清楚。

如前所述,该软件包有效。

但我对标记 /* start */ 之间的 6 行(即:6 行)感到困扰。和 /* end */ .我想用一行替换这些。但我还没有找到任何方法来做到这一点。

最佳答案

流水线函数的要点是提供 TABLE() 函数。我不认为有任何方法可以避免它。不幸的是,我们必须将其输出分配给 PL/SQL 变量。我们不能将流水线函数分配给这样的嵌套表 nt := more_rows;由于

PLS-00653: aggregate/table functions are not allowed in PL/SQL scope

所以 SELECT ... FROM TABLE()它一定要是。

我有一个稍微不同的解决方案供您考虑。我不知道它是否解决了你的根本问题。
create or replace package body tq84_pipelined as 

function more_rows return tq84_line pipelined is
begin

pipe row('ist');
pipe row('Eugen,');

return;

end more_rows;

function go return tq84_line pipelined is
nt1 tq84_line;
nt2 tq84_line;
nt3 tq84_line;
nt0 tq84_line;
begin

nt1 := tq84_line('Mein','Name');

select *
bulk collect into nt2
from table(more_rows);

nt3 := tq84_line('ich','weiss','von','nichts.');

nt0 := nt1 multiset union nt2 multiset union nt3;

for i in nt0.first..nt0.last
loop
pipe row(nt0(i));
end loop;

return;

end go;

end tq84_pipelined;
/

我相信您知道(但为了其他寻求者的利益)用于将集合组合在一起的 MULTISET UNION 语法是在 Oracle 10g 中引入的。

此版本的 GO() 产生与原始实现相同的输出:
SQL> select * from table( tq84_pipelined.go)
2 /

COLUMN_VALUE
-------------------------
Mein
Name
ist
Eugen,
ich
weiss
von
nichts.

8 rows selected.

SQL>

关于oracle - 流水线函数调用另一个流水线函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2779495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com