我有如下所述的设置
> create table earnings(earning_id number,
> col1 number,
> col2 number);
>
>create table trans(trans_id number,
> trans_attr1 number,
> trans_attr2 number);
>
>create or replace type trans_obj as object
> (trans_id number,
> trans_attr1 number,
> trans_attr2 number);
>
>create or replace type trans_coll as table of trans_obj;
>
>create or replace type earning_obj as object
> (
> earning_id number,
> col1 number,
> col2 number
> );
>
>create or replace type earnings_coll as table of earnings_obj;
>
>/
我有一个表函数如下
函数计算(trans_t trans_coll) return earnings_coll pipelined;
我想做类似下面的事情
>> function get_results(trans_t trans_coll)
>> return earnings_coll pipelined
>> as
>> l_earning_rec earnings_obj;
>>
>> begin
>>
>> for earning in (select * from table(calculate(trans_t)))
>> loop
>> l_earning_rec.extend();
>> // copy value from earning to l_earning_rec without having to copy each
>> // attribute individually
>>
>> pipe row(l_earning_rec);
>> end loop;
>>
>> return;
>> end get_results;
如果有办法,请告诉我。
此外,如果get_results是一个只会将记录插入收入表的程序,我该怎么办呢
insert into earnings
values (select * from table(calculate(trans_t)))
由于
答案 0 :(得分:1)
如果有帮助,你可以将功能更改为:
for earning in (select earnings_obj(earning_id, col1, col2) a
from table(calculate(trans_t)))
loop
pipe row(earning.a);
end loop;
至于你的插入,你只需将其写为:
insert into earnings
select * from table(calculate(trans_t));
答案 1 :(得分:0)
我一直在使用“10g PL / SQL编程指南”学习PL / SQL,我不认为有这样的事情。