Solution:
SQL> create table client1(Cno int primary key, Cname varchar(15), Address varchar(20),birthdate varchar(10));
SQL> create table poly(pno int primary key,decb varchar(10),mamt int check(mamt>0),pamt int check(pamt>0),pdate varchar(15));
SQL> create table cp(Cno int,pno int);
SQL> insert into client1 values(1,'shree','pune','23jan');
SQL> insert into poly values(1,'L-term',1000,500,'23jan');
SQL> insert into cp values(1,1);
SQL> set serveroutput on
create or replace function f1(abc in varchar) return number as xyz number;
begin
select sum(poly.mamt)into xyz from client1 ,poly,cp where client1.Cno=cp.Cno and poly.pno=cp.pno and cname='shree';
if sql% found then
return(xyz);
else
return null;
end if;
end f1;
/
Function created.
SQL> begin
dbms_output.put_line('amt-'||f1('shree'));
end;
/
amt-1000
2)Write a cursor which will display policy date wise client details.
SQL> set serveroutput on
SQL> declare
cursor c1 is select cname, address,pdate from client,poly,cp where client.cno=cp.cno and poly.pno=cp.pno order by pdate;
c c1%rowtype;
begin
open c1;
loop
fetch c1 into c;
exit when c1%notfound;
dbms_output.put_line(c.cname||''||c.address||''||c.pdate);
end loop;
close c1;
end;
/
shreepune23jan
ommumbai22feb
sairaichur21march
PL/SQL procedure successfully completed.
0 Comments