0

我有一个如下所述的设置

> 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)返回收益_coll流水线;

我想做类似下面的事情

>>  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)))

谢谢

4

2 回答 2

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));
于 2013-04-09T15:02:13.783 回答
0

我一直在使用“10g PL/SQL 编程指南”学习 PL/SQL,但我认为没有这样的东西。

于 2013-04-09T14:42:16.367 回答