0

I have a setup as mentioned below

> 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;
>
>/

I have a table function as below

function calculate(trans_t trans_coll) return earnings_coll pipelined;

I would like to do something like below

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

Please let me know if there is a way to do this.

Also if get_results was a procedure which would just insert records to earnings table,how can I do something like

insert into earnings 
   values (select * from table(calculate(trans_t)))

Thanks

2 Answers 2

1

you can change the function to this if it helps:

for earning in (select earnings_obj(earning_id, col1, col2) a
                 from table(calculate(trans_t)))
loop
   pipe row(earning.a);
end loop;

as for your insert you would just write it as:

insert into earnings 
select * from table(calculate(trans_t));
0

I've been studying PL/SQL using the "10g PL/SQL programming guide" and i dont think there is such thing like this.

2
  • Thanks Jeyvison, Which part exactly are you saying cannot be done?
    – Rohan
    Apr 9, 2013 at 14:51
  • Sorry ^^. You cant copy a row. You have to copy all the attributes or use a SELECT Statement if it helps..
    – Jeyvison
    Apr 9, 2013 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.