0

I have a type object as below Emptable type is empname,empid,rank

Then I have a Plsql function as below and this errors out. I need to run a sql select statement against the returned list of empids and load it the returned list. and below code keeps erroring..

create or replace function emp_details return emptable
  is
     l_result_col  emptable := emptable();
     n integer := 0;
     rxvalue number;
  begin
     for r in (select empname,empid from table)
     loop
        l_result_col.extend;
        n := n + 1;
        (select sum(xyz) into rxvalue from A inner join B on A.x=B.x and A.id=r.empid);
       l_result_col(n) := t_col(r.empname, r.empid,rxvalue);
     end loop;
     return l_result_col;
  end;
  /

Any Help is appreciated.. Thank you!

1
  • 1
    Saying what error you get might be helpful, no? And showing your type declarations. Do you get a compilation or runtime error? (It might just not like the brackets around the select, and I think your and should be a where). Commented Jul 22, 2013 at 20:38

2 Answers 2

1

Why not do it straightforward without involving PL/SQL code?

select t_col(r.empname, r.empid, sum(xyz))
bulk collect into l_result_col
from table r
left join (A join B on A.x = B.x) on A.id = r.empid
group by r.empname, r.empid;
Sign up to request clarification or add additional context in comments.

Comments

0

I think your select shouldn't be in parentheses. In this context it is not a subselect but a separate PL/SQL statement.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.