Q1)
create or replace function f1
return varchar is
subj varchar2(20);
Begin
select rp_subject into subj
from Research_Paper rp,R_RP rrp
where rp.rp_no=rrp.rp_no
and year=2013
and rp_level='national'
group by rp_subject having count(rp.rp_no)>=all(select count(rp.rp_no) from Research_Paper rp,R_RP rrp
where rp.rp_no=rrp.rp_no
and rp_level='national'
and year=2013);
return subj;
end;
Q2)
declare
cursor c1 is select distinct rp_level from Research_Paper;
cursor c2 is select r_name from Researcher;
cursor c3 (l Research_Paper.rp_level%type,rname Researcher.r_name%type) is select r.* from Researcher r1,Research_Paper r,R_RP rrp
where r.rp_no=rrp.rp_no and r1.r_no=rrp.r_no and r.rp_level=l and r1.r_name=rname ;
begin
for a in c1 loop
dbms_output.put_line(a.rp_level);
for b in c2 loop
dbms_output.put_line(b.r_name);
for c in c3(a.rp_level,b.r_name) loop
dbms_output.put_line(c.rp_no||' '||c.rp_title||' '||c.rp_subject||' '||c.rp_level);
end loop;
end loop;
end loop;
end;