Documente Academic
Documente Profesional
Documente Cultură
=============================================================================
SQL> create table ticket(tno int primary key,bookingdate varchar(10),fare int , traveling_date varchar(10),
cno int)
Table created.
SQL> insert into customer values(101,'Pravin','Pune',5645655);
1 row created.
SQL>set serveroutput on
SQL> begin
2 p1('5/4/15');
3 end;
4 /
Trigger created.
Relationship between Student and Competition is many-to-many with descriptive attribute rank and year.
Constraints:primary key, foreign key,primary key for third table(s_reg_no, comp_no, year),s_name and
comp_name should not be null,
Create a RDB in 3NF and write PL/SQL blocks in Oracle for the following:
1) Write a function which will accept s_reg_no of student and returns total number of competition in which
student has participated in a given year.
2) Write a cursor which will display year wise details of competitions held.(Use parameterized cursor)
Table created.
SQL> create table competition(compno int primary key,compname varchar(10) not null,comptype
varchar(10));
Table created.
Table created.
1 row created.
1 row created.
1 row created.
SQL> create or replace function fun1(nocomp in varchar) return number as nofcomp number;
2 begin
3 select count(competition.compno) into nofcomp from student1, competition, student1competition
where student1.sregno=student1competition.sregno and
competition.compno=student1competition.compno and student1.sregno=101;
4 if sql %found then
5 return(nofcomp);
6 else
7 return null;
8 end if;
9 end fun1;
10 /
Function created.
SQL> begin
2 dbms_output.put_line('no of competition-'||fun1(2015));
3 end;
4 /
no of competition-1
PL/SQL procedure successfully completed.
SQL>set serveroutput on
SQL>declare
2 cursor c1(yyyy student1competition.year%type)is select compname,comptype,year from
student1,competition,student1competition where student1.sregno=student1competition.sregno and
competition.compno=student1competition.compno order by year;
3 c c1%rowtype;
4 begin
5 open c1('&yyyy');
6 loop
7 fetch c1 into c;
8 exit when c1%notfound;
9 dbms_output.put_line(c.compname||' '||c.comptype||' '||c.year);
10 end loop;
11 close c1;
12 end;
13 /
Enter value for yyyy: 2015
old 5: open c1('&yyyy');
new 5: open c1('2015');
1) Write a procedure which will accept owner number and display details of all estates of given owner
which belongs to pune city.
2) Write a cursor which will display type wise estate details. (Use parameterized cursor)
SQL> create table owner(ono int primary key,oname varchar(15) not null,ocity varchar(15),ophno int);
Table created.
SQL> create table estate(eno int primary key,etype varchar(15),ecity varchar(15),eprice int,ono int
references owner);
Table created.
SQL> insert into owner values(1,'Lokesh','daund',2549696469);
1 row created.
SQL> begin
2 p3('pune');
3 end;
4 /
=============================================================================
Assignment no:-4
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
Consider the following entities and their relationship.
Bus(bus_no, capacity, source, destination)
Driver(driver_no, driver_name, license_no, addr, age, salary)
Relationship between Bus and Driver is many-to-many with descriptive attribute date_of_duty_allotted
and shift.
Create a RDB in 3NF and write PL/SQL blocks in Oracle for the following:
1) Write a function which will return name of driver having maximum salary.
2) Write a cursor which will display date wise bus and their driver details.
SQL> create table bus(busno int primary key,capacity int,source varchar(10),destination varchar(10));
Table created.
SQL> create table driver(dno int primary key,dname varchar(10) not null,licenceno int,addr
varchar(10),age int,salary int);
Table created.
SQL> create table busdriver(busno int,dno int, dateofdutyallotted varchar(10), shift varchar(15));
Table created.
Function created.
SQL> begin
2 dbms_output.put_line('name-'||fun('dname'));
3 end;
4 /
name-omkar
PL/SQL procedure successfully completed.
SQL> Set serveroutput on
SQL> Declare
2 Cursor c1 is select capacity,source,destination,dname,licenceno,age,salary from bus, driver, busdriver
where bus.busno=busdriver.busno and driver.dno=busdriver.dno;
3 C c1%rowtype;
4 Begin
5 Open c1;
6 Loop
7 Fetch c1 into c;
8 Exit when c1%notfound;
9 Dbms_output.put_line(c.capacity||' '||c.source||' '||c.destination||' '||c.dname||' '||c.licenceno||' '||
c.age||' '||c.salary);
10 End loop;
11 Close c1;
12 End;
13 /
14 delhi daund ram 6464 25 4969
27 daund delhi sam 5454 30 5535
20 daund pune shasi 4452 21 5545
15 nasik mumbai omkar 5554 35 6000
30 hadapsar katraj shubham 5448 26 4444
PL/SQL procedure successfully completed.
=============================================================================
Assignment no:-5
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
Create a RDB in 3NF and write PL/SQL blocks in Oracle for the following:
1) Write a package, which consists of one procedure and one function. Pass drug number as a parameter
to procedure and display details of that drug. Pass city as a parameter to a function and return total
number of medical_store in given city.
2) Write a trigger that restricts insertion and updation of drug having price less than zero. (Raise user
defined exception and give appropriate message)
SQL> create table drug(dno int primary key,dname varchar(15) not null,company varchar(15),price int);
Table created.
SQL> create table medicalstore(mno int primary key,mname varchar(15) not null,mcity varchar(15),phno
int);
Table created.
SQL> create table drugmedicalstore(dno int,mno int,quantity int);
Table created.
SQL> insert into drug values(101,'insepton','malform',6545);
1 row created.
SQL> Select * from drug;
DNO DNAME COMPANY PRICE
---------- --------------- --------------- ----------
101 insepton malform 6545
102 cojka sector 1895
103 acen mankind 3652
104 syndron sector 5452
105 santin mankind 9824
------------------------------------------------------------
105 5 620
--------------------------------------
SQL> Set serveroutput on
SQL> Create or replace trigger t5 before insert or update on drug
2 For each row
3 Begin
4 If(:new.price<=0) then
5 Raise_application_error(-20001,'price>0');
6 End if;
7 End;
8 /
Trigger created.
================================================================================
Assignment no :-6
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
1 row created.
SQL> insert into passenger values(2,'harsh','delhi',18);
1 row created.
SQL> insert into passenger values(3,'vishal','daund',20);
1 row created.
SQL> insert into passenger values(4,'roshan','hadapsar',19);
1 row created.
SQL> insert into passenger values(5,'shashikant','pune',19);
1 row created.
SQL> insert into passenger values(6,'akash','daund',19);
1 row created.
SQL> select * from passenger;
PNO PNAME ADDR AGE
---------- --------------- --------------- ----------
1 lokesh daund 18
2 harsh delhi 18
3 vishal daund 20
4 roshan hadapsar 19
5 shashikant pune 19
6 akash daund 19
----------------------------------------------------
SQL> insert into trainpassenger values(101,1,'12/5/15',14,700);
1 row created.
SQL> insert into trainpassenger values(101,2,'12/5/15',15,700);
1 row created.
SQL> insert into trainpassenger values(102,3,'8/12/11',17,625);
1 row created.
SQL> insert into trainpassenger values(103,4,'10/9/15',31,500);
1 row created.
SQL> insert into trainpassenger values(104,5,'9/4/13',24,250);
1 row created.
SQL> insert into trainpassenger values(105,6,'3/5/14',45,300);
1 row created.
SQL> select * from trainpassenger;
TNO PNO TPDATE SEATNO AMT
---------- ---------- ------------ ---------- ----------
101 1 12/5/15 14 700
101 2 12/5/15 15 700
102 3 8/12/11 17 625
103 4 10/9/15 31 500
104 5 9/4/13 24 250
105 6 3/5/14 45 300
--------------------------------------------------------------
SQL> set serveroutput on
SQL> create or replace function fun1(pn in varchar) return varchar as maxpass varchar(15);
2 begin
3 select max(noofpassenger) into maxpass from train;
4 if sql %found then
5 return(maxpass);
6 else
7 return null;
8 end if;
9 end ;
10 /
Function created.
SQL> begin
2 dbms_output.put_line('no of competition-'||fun1('12/5/15'));
3 end;
4 /
no of competition-2
PL/SQL procedure successfully completed.
================================================================================
Assignment no :-7
================================================================================
Assignment no :-8
SQL> create table university(uno int primary key,uname varchar(20) not null,ucity varchar(15));
Table created.
SQL> create table college(cno int primary key,cname varchar(20) not null,ccity varchar(15),yearofest
int,uno int);
Table created.
SQL> insert into university values(101,'pune university','pune');
1 row created.
SQL> insert into university values(102,'delhi university ','delhi');
1 row created.
SQL> insert into university values(103,'mumbai university ','mumbai');
1 row created.
SQL> insert into university values(104,'nagpur university ','nagpur');
1 row created.
SQL> insert into university values(105,'sangli university ','sangli');
1 row created.
SQL> select * from university;
UNO UNAME UCITY
---------- -------------------- ---------------
101 pune university pune
102 delhi university delhi
103 mumbai university mumbai
104 nagpur university nagpur
105 sangli university sangli
-------------------------------------------------
SQL> insert into college values(1,'pune university','pune',1997,101);
1 row created.
SQL> insert into college values(2,'delhi university ','delhi',1997,102);
1 row created.
SQL> insert into college values(3,'mumbai university ','mumbai',1991,103);
1 row created.
SQL> insert into college values(4,'nagpur university ','nagpur',1968,104);
1 row created.
SQL> insert into college values(5,'sangli university ','sangli',1987,105);
1 row created.
SQL> select * from college;
CNO CNAME CCITY YEAROFEST UNO
---------- -------------------- --------------- ---------- ----------
1 pune university pune 1997 101
2 delhi university delhi 1997 102
3 mumbai university mumbai 1991 103
4 nagpur university nagpur 1968 104
5 sangli university sangli 1987 105
---------------------------------------------------------------------------
SQL> set serveroutput on
SQL> declare
2 cursor c2(unm university.uno%type) is select uname,cname,ccity,yearofest from university,college
where university.uno=college.uno and university.uno=102;
3 c c2%rowtype;
4 begin
5 open c2('&unm');
6 loop
7 fetch c2 into c;
8 exit when c2%notfound;
9 dbms_output.put_line(c.uname||''||c.cname||''||c.ccity||''||c.yearofest);
10 end loop;
11 close c2;
12 end;
13 /
================================================================================
Assignment no :-9
================================================================================
Assignment no :-11
SQL> create table researcher(rno int primary key,rname varchar(15) not null,rcity varchar(15));
Table created.
SQL> create table researchpaper(rpno int primary key,rptitle varchar(20) not null,rpsubject varchar(15),
rplevel varchar(15));
Table created.
SQL> create table researcherpaper(rno int, rpno int,year int);
Table created.
SQL> insert into researcher values(101,'lokesh','daund');
1 row created.
SQL> insert into researcher values(102,'harsh','delhi');
1 row created.
SQL> insert into researcher values(103,'vishal','daund');
1 row created.
SQL> insert into researcher values(104,'roshan','mumbai');
1 row created.
SQL> insert into researcher values(105,'shashikant','pune');
1 row created.
SQL> select * from researcher;
RNO RNAME RCITY
---------- --------------- ---------------
101 lokesh daund
102 harsh delhi
103 vishal daund
104 roshan mumbai
105 shashikant pune
--------------------------------------------
================================================================================
Assignment no :-12
2 b+ 1 14/4/2015 102
3 o+ 2 25/9/2013 103
4 a- 3 11/3/2012 104
-----------------------------------------------------------------
================================================================================
Assignment no :-13
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
1 row created.
SQL> select * from policyinfo;
PNO PNAME MATURITYAMT PREMAMT POLICYTERM
---------- --------------- ----------- ---------- ----------
1 abc 60000 55000 5
2 jkl 50000 30000 4
3 mno 80000 49000 9
4 pqr 20000 25000 6
5 xyz 40000 45000 7
----------------------------------------------------------------
SQL> insert into clientpolicy values(101,1,'12/5/15',2015);
1 row created.
SQL> select * from clientpolicy;
CNO PNO DATEOFPURCHASE YEAR
---------- ---------- --------------- ----------
101 1 12/5/15 2015
102 2 8/12/11 2011
103 3 9/4/13 2013
104 4 10/9/15 2015
105 5 3/5/14 2014
------------------------------------------------------
SQL> set serveroutput on
SQL> create or replace procedure p2(n in varchar) as cursor c1 is select cname, pname, maturityamt,
premamt, policyterm, year from client, policyinfo, clientpolicy where client.cno=clientpolicy.cno and
policyinfo.pno=clientpolicy.pno and cname='harsh';
2 c c1%rowtype;
3 begin
4 open c1;
5 dbms_output.put_line('cname'||' '||'pname'||' '||'maturityamt '||''||'premamt '||''||'policyterm');
6 loop
7 fetch c1 into c;
8 exit when c1%notfound;
9 if(c.year=n) then
10 dbms_output.put_line(c.cname||' '||c.pname||' '||c.maturityamt||' '||c.premamt||' '||c.policyterm);
11 end if;
12 end loop;
13 close c1;
14 end;
15 /
Procedure created.
SQL> begin
2
3 end;
4 /
cname pname maturityamt premamt policyterm
harsh jkl 50000 30000 4
PL/SQL procedure successfully completed.
================================================================================
Assignment no :-14
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
================================================================================
Assignment no :-15
================================================================================
Assignment no :-16
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
================================================================================
Assignment no :-17
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
SQL> create table student1(sregno int primary key, sname varchar(15),sclass varchar(10));
Table created.
SQL> create table competition(compno int primary key, compname varchar(10) not null, comptype
varchar(10));
Table created.
SQL> create table student1competition(sregno int, compno int,rank int,year int);
Table created.
SQL> insert into student1 values(101,'Lokesh','sybca');
1 row created.
SQL> SELECT * FROM STUDENT1;
SREGNO SNAME SCLASS
---------- --------------- ----------
101 Lokesh sybca
102 Roshan sybca
103 Sashikant sybca
104 Ashish sybca
105 Omkar sybca
------------------------------------------
SQL> insert into competition values(1,'Paint','academic');
1 row created.
SQL> select * from competition;
COMPNO COMPNAME COMPTYPE
---------- ---------- ----------
1 Paint academic
2 Foot Ball Sports
3 Quiz academic
4 Running Sports
5 Chess academic
---------------------------------------------
SQL> insert into student1competition values(101,1,2,2013);
1 row created.
SQL> select * from student1competition;
SREGNO COMPNO RANK YEAR
---------- ---------- ---------- ----------
101 1 2 2013
102 2 3 2012
103 3 1 2015
104 4 2 2011
105 5 1 2014
SQL> set serveroutput on
SQL> create or replace procedure p1(n in varchar) as cursor c1 is select compname, comptype, year
from student1, competition, student1competition where student1.sregno=student1competition.sregno and
competition.compno=student1competition.compno and comptype='academic';
2 c c1%rowtype;
3 begin
4 open c1;
5 dbms_output.put_line('compname'||' '||'comptype');
6 loop
7 fetch c1 into c;
8 exit when c1%notfound;
9 if(c.year=n) then
10 dbms_output.put_line(c.compname||' '||c.comptype);
11 end if;
12 end loop;
13 close c1;
14 end;
15 /
Procedure created.
SQL> begin
2 p1(2013);
3 end;
4 /
compname comptype
Paint academic
PL/SQL procedure successfully completed.
SQL> set serveroutput on
SQL> create or replace trigger t2 before insert or update on student1competition
2 for each row
3 begin
4 if(:new.rank>3) then
5 raise_application_error(-20001,'rank should be 1, 2 or 3.');
6 end if;
7 end;
8 /
Trigger created.
SQL> insert into student1competition values(106,6,4,2015);
insert into student1competition values(106,6,4,2015)
*
ERROR at line 1:
ORA-20001: rank should be 1, 2 or 3.
ORA-06512: at "SCOTT.T2", line 3
ORA-04088: error during execution of trigger 'SCOTT.T2'
================================================================================
Assignment no :-18
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
Function created.
SQL> begin
2 dbms_output.put_line('no of owner- '||fun1('delhi'));
3 end;
4 /
no of owner- 1
PL/SQL procedure successfully completed.
SQL> set serveroutput on
SQL> create or replace trigger t4 before insert or update on estate
2 for each row
3 begin
4 if(:new.eprice<100000)then
5 raise_application_error(-20001,'price should be more than 1 lakh.');
6 end if;
7 end;
8 /
Trigger created.
SQL> insert into estate values(107,'land','delhi',14000,7);
insert into estate values(107,'land','delhi',14000,7)
*
ERROR at line 1:
ORA-20001: price should be more than 1 lakh.
ORA-06512: at "SCOTT.T4", line 3
ORA-04088: error during execution of trigger 'SCOTT.T4'
================================================================================
Assignment no :-19
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
Consider the following entites and their relationship.
Bus (bus_no, capacity, source, destination)
Driver(driver_no, driver_name, license_no, addr, age, salary)
Relationship between Bus and Driver is many-to-many with descriptive attribute date_of_duty_allotted
and shift
Constraints: primary key, foreign key,
Primary key for third table (bus_no , driver_no, date_of_duty_allotted),
driver_name should not be null,
shift can be morning or evening.
Create a RDB in 3Nf and write PL/SQL blocks in Oracle for the following:
1) Write a procedure which will display bus_no and name of allotted driver on given date and shift.
2) Write a trigger that restricts insertion or updation of driver table if driver age is less than 18 or
greater than 50. (Raise user defined exception and give appropriate message.)
SQL> create table bus(busno int primary key,capacity int,source varchar(10),destination varchar(10));
Table created.
SQL> create table driver(dno int primary key,dname varchar(10) not null,licenceno int,addr
varchar(10),age int,salary int);
Table created.
SQL> create table busdriver(busno int,dno int, dateofdutyallotted varchar(10), shift varchar(15));
Table created.
================================================================================
Assignment no :-20
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
Create a RDB in 3NF and write PL/SQL blocks in Oracle for the following:
1) Write a procedure which will display bus_no and name of allotted driver on given date and shift.
2) Write a trigger that restricts insertion or updation of driver table if driver age is less than 18 or
greater than 50. (Raise user defined exception and give appropriate message).
SQL> create table drug(dno int primary key,dname varchar(15) not null,company varchar(15),price int);
Table created.
SQL> create table medicalstore(mno int primary key,mname varchar(15) not null,mcity varchar(15),phno
int);
Table created.
SQL> create table drugmedicalstore(dno int,mno int,quantity int);
Table created.
SQL> insert into drug values(101,'insepton','malform',6545);
1 row created.
SQL> Select * from drug;
DNO DNAME COMPANY PRICE
--------- --------------- --------------- ----------
101 insepton malform 6545
102 cojka sector 1895
103 acen mankind 3652
104 syndron sector 5452
105 santin mankind 9824
------------------------------------------------------------
SQL> insert into medicalstore values(1,'new strom','daund',2549696469);
1 row created.
SQL> Select * from medicalstore;
MNO MNAME MCITY PHNO
--------- --------------- --------------- ----------
1 new strom daund 2549696469
2 matrix pune 459632581
3 nitro nasik 2584
4 cronicle nagpur 54862
5 mediplus mumbai 85487
------------------------------------------------------------
================================================================================
Assignment no :-21
================================================================================
Assignment no :22
================================================================================
Assignment no :-23
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
SQL> create table university(uno int primary key,uname varchar(20) not null,ucity varchar(15));
Table created.
SQL> create table college(cno int primary key,cname varchar(20) not null,ccity varchar(15),yearofest
int,uno int);
Table created.
SQL> insert into university values(101,'pune university','pune');
1 row created.
SQL> select * from university;
UNO UNAME UCITY
---------- -------------------- ---------------
101 pune university pune
102 delhi university delhi
103 mumbai university mumbai
104 nagpur university nagpur
105 sangli university sangli
-------------------------------------------------
SQL> insert into college values(1,'pune college ','pune','14 apr 1997',101);
1 row created.
SQL> select * from college;
CNO CNAME CCITY YEAROFEST UNO
--------- -------------------- --------------- --------- ----------
1 pune college pune 14-APR-97 101
2 delhi college delhi 25-NOV-91 102
3 mumbai college mumbai 11-JAN-93 103
4 nagpur college nagpur 31-OCT-68 104
5 sangli college sangli 27-JUL-87 105
--------------------------------------------------------------------------
SQL> set serveroutput on
SQL> create or replace procedure p1(n in varchar) as cursor c1 is select uname, cname, ccity, yearofest,
ucity from university,college where university.uno=college.uno;
2 c c1%rowtype;
3 begin
4 open c1;
5 dbms_output.put_line('uname'||' '||'cname'||' '||'ccity'||' '||'yearofest');
6 loop
7 fetch c1 into c;
8 exit when c1%notfound;
9 if(c.ucity=n) then
10 dbms_output.put_line(c.uname||' '||c.cname||' '||c.ccity||' '||c.yearofest);
11 end if;
12 end loop;
13 end;
14 /
Procedure created.
SQL> begin
2 p1('delhi');
3 end;
4 /
uname cname ccity yearofest
delhi university delhi college delhi 25-NOV-91
PL/SQL procedure successfully completed.
SQL> set serveroutput on
SQL> create or replace trigger t3 before insert or update on college
2 for each row
3 declare
4 d1 varchar(10);
5 d2 varchar(10);
6 begin
7 d1:=to_char(:new.yearofest,'yyyy');
8 d2:=to_char(sysdate,'yyyy');
9 if(d1>d2) then
10 raise_application_error(-20001,'investment date should be less than current date.');
11 end if;
12 end;
13 /
Trigger created.
SQL> insert into college values(1,'pune university','pune','1 jan 2016',101);
insert into college values(1,'pune university','pune','1 jan 2016',101)*
ERROR at line 1:
ORA-20001: investment date should be less than current date.
ORA-06512: at "SCOTT.T3", line 8
ORA-04088: error during execution of trigger 'SCOTT.T3'
================================================================================
Assignment no :-24
================================================================================
Assignment no :-25
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
================================================================================
Assignment no :-26
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
Table created.
SQL> create table researcherpaper(rno int, rpno int,year int);
Table created.
SQL> insert into researcher values(101,'lokesh','daund');
1 row created.
SQL> select * from researcher;
RNO RNAME RCITY
--------- --------------- ---------------
101 lokesh daund
102 harsh delhi
103 vishal daund
104 roshan mumbai
105 shashikant pune
-------------------------------------------
SQL> insert into researchpaper values(1,'hardware','computer','international');
1 row created.
SQL> select * from researchpaper;
RPNO RPTITLE RPSUBJECT RPLEVEL
---------- -------------------- --------------- ---------------
1 hardware computer international
2 software computer international
3 LCD electronics national
4 shares finance national
5 TV electronics state
-----------------------------------------------------------------
SQL> insert into researcherpaper values(101,1,2015);
1 row created.
SQL> select * from researcherpaper;
RNO RPNO YEAR
---------- ---------- ----------
101 1 2015
102 2 2015
103 3 2011
104 4 2012
105 5 2013
-----------------------------------
SQL> set serveroutput on
SQL> create or replace function fun1(ns in varchar) return varchar as nmofs varchar(15);
2 begin
3 select (rpsubject) into nmofs from researchpaper, researcherpaper where
researchpaper.rpno=researcherpaper.rpno and year=2012;
4 if sql %found then
5 return(nmofs);
6 else
7 return null;
8 end if;
9 end ;
10 /
Function created.
SQL> begin
2 dbms_output.put_line('subject is '||fun1('national'));
3 end;
4 /
subject is finance
PL/SQL procedure successfully completed.
SQL> set serveroutput on
SQL> declare
2 cursor c1(rwise researcher.rname%type)is select rptitle, rpsubject, rplevel, rname from researcher,
researchpaper, researcherpaper where researcher.rno=researcherpaper.rno and
researchpaper.rpno=researcherpaper.rpno order by rplevel;
3 c c1%rowtype;
4 begin
5 open c1('&rwise');
6 loop
7 fetch c1 into c;
8 exit when c1%notfound;
9 dbms_output.put_line(c.rname||' '||c.rptitle||' '||c.rpsubject||' '||c.rplevel);
10 end loop;
11 close c1;
12 end;
13 /
Enter value for rwise: lokesh
old 5: open c1('&rwise');
new 5: open c1('lokesh');
lokesh hardware computer international
harsh software computer international
vishal LCD electronics national
roshan shares finance national
shashikant TV electronics state
PL/SQL procedure successfully completed.
================================================================================
Assignment no :-27
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
================================================================================
Assignment no :-28
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-
Create a RDB in 3NF and write PL/SQL blocks in Oracle for the following:
1) Write a function which will return name of policy taken by minimum number of clients.
2) Write a cursor which will display client wise policy details. (Use parameterized cursor)
SQL> create table client(cno int primary key,cname varchar(15) not null,addr varchar(15),birthdate
varchar(15));
Table created.
SQL> create table policyinfo(pno int primary key,pname varchar(15) not null,maturityamt int,premamt
int,policyterm int);
Table created.
SQL> create table clientpolicy(cno int, pno int,dateofpurchase varchar(15),year int);
Table created.
SQL> insert into client values(101,'lokesh','daund','27/7/97');
1 row created.
SQL> select * from client;
CNO CNAME ADDR BIRTHDATE
---------- --------------- --------------- ---------------
101 lokesh daund 27/7/97
102 harsh delhi 14/4/97
103 vishal daund 15/9/95
104 roshan hadapsar 21/6/96
105 shashikant pune 30/5/97
----------------------------------------------------------
SQL> insert into policyinfo values(1,'abc',60000,55000,5);
1 row created.
SQL> select * from policyinfo;
PNO PNAME MATURITYAMT PREMAMT POLICYTERM
--------- --------------- ----------- ---------- ----------
1 abc 60000 55000 5
2 jkl 50000 30000 4
3 mno 80000 49000 9
4 pqr 20000 25000 6
5 xyz 40000 45000 7
----------------------------------------------------------------
SQL> insert into clientpolicy values(101,1,'12/5/15',2015);
1 row created.
SQL> select * from clientpolicy;
CNO PNO DATEOFPURCHASE YEAR
---------- ---------- --------------- ----------
101 1 12/5/15 2015
102 2 8/12/11 2011
103 3 9/4/13 2013
104 4 10/9/15 2015
105 5 3/5/14 2014
------------------------------------------------------
SQL> set serveroutput on
SQL> create or replace function fun1(pn in varchar) return varchar as minp varchar(15);
2 begin
3 select (pname) into minp from client, policyinfo, clientpolicy where client.cno=clientpolicy.cno and
policyinfo.pno=clientpolicy.pno and clientpolicy.cno=(select min(clientpolicy.cno) from clientpolicy);
4 if sql %found then
5 return(minp);
6 else
7 return null;
8 end if;
9 end ;
10 /
Function created.
SQL> begin
2 dbms_output.put_line('minimum no. of clients policy is'||fun1('pname'));
3 end;
4 /
minimum no. of clients policy is abc
PL/SQL procedure successfully completed.
SQL> set serveroutput on
SQL> declare
2 cursor c1(cwise client.cname%type)is select cname, pname, maturityamt, premamt, policyterm from
client, policyinfo, clientpolicy where client.cno=clientpolicy.cno and policyinfo.pno=clientpolicy.
pno;
3 c c1%rowtype;
4 begin
5 open c1('&cwise');
6 loop
7 fetch c1 into c;
8 exit when c1%notfound;
9 dbms_output.put_line(c.cname||' '||c.pname||' '||c.maturityamt||' '||c.premamt||' '||c.policyterm);
10 end loop;
11 close c1;
12 end;
13 /
Enter value for cwise: harsh
old 5: open c1('&cwise');
new 5: open c1('harsh');
lokesh abc 60000 55000 5
harsh jkl 50000 30000 4
vishal mno 80000 49000 9
roshan pqr 20000 25000 6
shashikant xyz 40000 45000 7
PL/SQL procedure successfully completed.
================================================================================
Assignment no :-29
================================================================================
Assignment no :-30
Name :- Datkhile Shubhangi vilas
Class :-SY BBA (CA)
Subject :- Relational Database Management System
Assignment Name :-