这是一个包含两个流水线功能的包:
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;
/
Run Code Online (Sandbox Code Playgroud)
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;
/
Run Code Online (Sandbox Code Playgroud)
重要的是,去那种调用more_rows与for next in ...之间/* start */和/* end */
我可以使用如下包:
select * from table(tq84_pipelined.go);
Run Code Online (Sandbox Code Playgroud)
这是所有罚款和花花公子,但我希望我能代替之间的界限/* start */,并/* end */用一个简单的调用more_rows.
然而,这显然是不可能的,因为它产生PLS-00221:'MORE_ROWS'不是程序或未定义.
所以,我的问题是:真的没有办法简化循环吗?
编辑
显然,从目前为止的答案来看,我的问题并不清楚.
包装,如所述的工作.
但是我对标记/* start */和标记之间的6(即:SIX)线感到困扰/* end */.我想用一条线替换它们.但我没有找到任何办法.
流水线函数的要点是提供TABLE()函数.我认为没有办法避免它.不幸的是,我们必须将其输出分配给PL/SQL变量.我们无法分配管道函数的嵌套表像这样nt := more_rows;因
PLS-00653: aggregate/table functions are not allowed in PL/SQL scope
Run Code Online (Sandbox Code Playgroud)
所以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;
/
Run Code Online (Sandbox Code Playgroud)
我确信你知道(但是为了其他求职者的利益)在Oracle 10g中引入了用于glomming集合的MULTISET UNION语法.
此版本的GO()产生与原始实现相同的输出:
SQL> select * from table( tq84_pipelined.go)
2 /
COLUMN_VALUE
-------------------------
Mein
Name
ist
Eugen,
ich
weiss
von
nichts.
8 rows selected.
SQL>
Run Code Online (Sandbox Code Playgroud)