Q1) create or replace function f1
return varchar is
pnm varchar(15);
begin
select p_name into pnm
from person,investment
where person.p_no=investment.p_no
group by p_name having sum(i_amt)>=all(select sum(i_amt) from investment,person
where person.p_no=investment1.p_no
group by p_name);
return pnm;
end;
Q2)
Declare
cursor c1 is select p_name from pers;
cursor c2 (pnm person.p_name%type) is
select inv_name,inv_amt,inv_date
from pers,investment
where person.p_no=investment.p_no
and p_name=pnm;
r1 c1%rowtype;
r2 c2%rowtype;
Begin
open c1;
loop
fetch c1 into r1;
exit when c1%notfound;
dbms_output.put_line(r1.p_name);
open c2(r1.p_name);
loop
fetch c2 into r2;
exit when c2%notfound;
dbms_output.put_line(r2.inv_name||r2.inv_amt||r2.inv_date);
end loop;
close c2;
end loop;
close c1;
end;