Sie sind auf Seite 1von 90

SQL QUERIES: 1.

Display the names of all employees who are workintg in deptno=10; Select ename from e104 where deptno=10; 2. Display employee number & name for all employees who earn commission. Select eno,ename from e104 where comm Is not null; 3. Display names of employes who dont earn any commission. Select ename from e104 where comm. Is null; 4. Display the names of the employees who are working as clerk,salesman&analyst and salary morethen 3000. Select ename from emp where job in(clerk,salesman,analyst and sal>3000; 5. Display the list of users in your database. Select * from all_users; 6. Display name of employees whose name starts with s. Seleft ename from e104 where ename like s%; 7. Display the employee names whose name ends with s. Select ename from e104 where ename like %s; 8. Display total salary being paid to all employes Select max(sal) from e104; 9. Display maximum salary from employee tablel. Select max(sal) from e104; 10. Display minimum salary from employee table. Select min(sal) frome104; 11. Display average salary from employee table. Select round(avg(sal)) from e104; 12. Display average salary drawn by managers. Select avg(sal) from e104 where job=Manager; 13. Display total salary drawn by analyst working in deptno=10. Select sum(sal) from e104 where deptno=10 and job=Analyst;

Page No: 1

14. Dislay various jobs & total no. of employees with each job group. Select distinct job, count(*) from e104 group by job; 15. Display deptno.s and maximum salary for each department. Select dptno,max(sal) from e104 group by deptno; 16. Display various jobs and total salary for each job. Select job,min(sal) from e104 group by sal; 17. Display deptnos with morethan three employees in each department. Select distinct deptno,count(*) from e104 having count(*)>3; 18. Display various jobs along with total salary for each of the job where total salary is greater than 4000. Select job,max(sal) from e104 where max(sal)>4000 group by job; 19. Display your age in days. Select sysdate-hiredate from emp; 20. Display deptnos and total salary for each department. Select deptno,sum(sal) from e104 group by deptno;

Page No: 2

Create a table to represent sb-account of a bank consisting of account-no, customer-name, balance-amount. Write a PL/SQL block to implement deposit and withdraw. Withdraws should not be allowed if the balance goes below Rs.1000.
1.

SQL> create table sb_account(acno number(5),cname varchar2(20),balance number(7,2)); Table created. SQL> insert into sb_account values(&acno,'&cname',&balance); SQL> select* from sb_account; ACNO ---------1001 1002 1005 1006 1003 1004 1009 CNAME BALANCE -------------------- ---------siva 5000 Ramesh 6000 Ramu 10000 Satya 12000 Rajesh 1000 Teja 3000 Ramana 300

SQL> ed bramar1

declare amt number(5); acc sb_account.acno%type; begin acc:=&acno; amt:=&deposited_amount; update sb_account set balance=balance+amt where acno=acc; commit; end;

SQL> @bramar1 10 / Enter value for acno: 1004 Enter value for deposited_amount: 500 PL/SQL procedure successfully completed. SQL> select* from sb_account; ACNO ---------1001 1002 1005 1006 1003 1004 1009 CNAME BALANCE -------------------- ---------siva 5000 Ramesh 6000 Ramu 10000 Satya 12000 Rajesh 1000 Teja 3500 Ramana 300

Page No: 3

SQL> ed bramar1_b

declare acc sb_account.acno%type; sbal number(7,2); amt number(5); begin acc:=&accno; amt:=&withdrawn_amount; select balance into sbal from sb_account where acno=acc; if sbal<=1000 then dbms_output.put_line('withdrawn fails'); elsif amt>sbal then dbms_output.put_line('withdrawn fails'); else update sb_account set balance=balance-amt where acno=acc; end if; end;

SQL> @bramar1_b 16 / Enter value for accno: 1001 Enter value for withdrawn_amount: 500 PL/SQL procedure successfully completed. SQL> select* from sb_account; ACNO ---------1001 1002 1005 1006 1003 1004 1009 CNAME BALANCE -------------------- ---------siva 4500 Ramesh 6000 Ramu 10000 Satya 12000 Rajesh 1000 Teja 3500 Ramana 300

Page No: 4

2.

Create The following two tables : College-info Faculty-info College-info consists of fields : college-code, college-name, address Faculty-info consists of fields : college-code, faculty-code, faculty-name, qualification, experience-in-no-of-years, address. The field college-code is foreign key. (a) Design a form to accept the data from the user. (b) Generate queries to do the following : (i) List all those faculty members whose experience is greater than or equal to 10 years and have M. Tech degree. (ii) List all those faculty members, who have at least 10 years of experience but do not have M. Tech degree.
SQL> create table college_info(ccode number(5)primary key,cname varchar2(20), address varchar2(20)); Table created. SQL> create table faculty_info(ccode number(5) references college_info(ccode),fcode number(5),fname varchar2(20),qualification varchar2(20),experiance number(2),address varchar2(20)); Table created.

Page No: 5

Page No: 6

Page No: 7

Page No: 8

Page No: 9

Page No: 10

Page No: 11

SQL> insert into college_info values(&ccode,'&cname','&address'); Sql> insert into faculty_info values(&ccode number(5) references college_info(ccode),&fname,&qualification,&experience,&address); SQL> SELECT * FROM COLLEGE_INFO; CCODE ---------1001 1003 1002 1004 1005 1006 CNAME -------------------AURORA MIPGS OU PG CAMPUS OU MAIN CAMPUS BADRUKA RBVRR ADDRESS -------------------DILSUKHNAGAR SAIDABAD SAIFABAD VIDYANAGAR KACHIGUDA ABIDS

Sql> select fname from faculty_info where experience>=10 and qualification like M.Tech.; Sql> select fname from faculty_info where experience>10 and qualification not like M.Tech.;

3.

Create the following tables for Library Information System : Page No: 12

Book10 : (accession-no, title, publisher, author, status) Status could be issued, present in the library, sent for binding, and cannot be issued. Write a trigger which sets the status of a book to "cannot be issued", if it is published 20 years back.

Sql> create table book10(accession_no number(5),title varchar2(20),publisher varchar2(30),author varchar2(20),status varchar2(20)); Table created SQL> insert into book10 values(&accession_no,'&title','&publisher',&author,'&status');
SQL> select * from book10;
ACCESSION_NO -----------100 101 102 103 105 104 106 107 109 110 TITLE -------------------SE OR DAA DAA SE OR OR SE JAVA JAVA PUBLISHER YEAR DOP STATUS -------------------- ---------- --------- -------------TATA MC HILL 1999 12-JAN-99 ISSUED S.CHAND 2005 15-JUN-05 ISSUED TATA MC HILL 1088 NOT ISSUED TATA MC HILL 2005 13-JAN-04 ISSUED TATA MC HILL 2003 13-JAN-02 ISSUED S.CHAND 1988 ISSUED S.CHAND 2005 ISSUED TATA MC HILL 1999 14-AUG-98 ISSUED TATA MC HILL 1965 10-JAN-70 cannot be issued TATA MC HILL 1965 10-JAN-77 ISSUED

Sql> ed bramar3

create or replace trigger cissued before insert on book10 for each row begin update book10 set status='cannot be issued' where round((sysdate-dop)/365)>=20; end;

SQL> @bramar3 7 / Trigger created.

Page No: 13

4.

Create the following tables for Library Information System : Book10(accession-no, title, publisher, author, status, date-ofpurchase) Status could be issued, present in the library, sent for binding, and account be issued. (a) Create a form to accept the data from the user Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) List all those books which are new arrivals. The books which are acquired during the last 6 months are categorized as new arrivals. (ii) List all those books that cannot be issued and purchased 20 years ago.
Sql> create table book10(accession_no number(5),title varchar2(20),publisher varchar2(30),author varchar2(20),status varchar2(20),dop date); Table created

SQL> insert into book10 values(&accession_no,'&title','&publisher',&author,'&status',&dop);


SQL> select * from book10;
ACCESSION_NO -----------100 101 102 103 105 104 106 107 109 110 TITLE -------------------SE OR DAA DAA SE OR OR SE JAVA JAVA PUBLISHER YEAR DOP STATUS -------------------- ---------- --------- ---------------TATA MC HILL 1999 12-JAN-99 ISSUED S.CHAND 2005 15-JUN-05 ISSUED TATA MC HILL 1088 NOT ISSUED TATA MC HILL 2005 13-JAN-04 ISSUED TATA MC HILL 2003 13-JAN-02 ISSUED S.CHAND 1988 ISSUED S.CHAND 2005 ISSUED TATA MC HILL 1999 14-AUG-98 ISSUED TATA MC HILL 1965 10-JAN-70 cannot be issued TATA MC HILL 1965 10-JAN-77 ISSUED

Sql> select title from book10 where months_between(sysdate,dop)<=6; Sql> select title from book10 where round((sysdate-dop)/365)>=20;

5.

Create the following tables : Page No: 14

Student20(roll-no, name, date-of-birth, course-id) Course20 (Course-id, name, fee, duration) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) List all those students who are greater than 18 years of age and have opted for MCA course. (iii) List all those courses whose fee is greater than that of MCA course.
SQL> create table student20(roll_no number(4)primary key,dob date,course_id number(6)); Table created. Sql> create table course20(course_id number(6)references course20(course_id),name varchar2(20),fee number(5),duration varchar2(20),status varchar2(20)); Table created.

SQL> insert into student20 values(&roll_no,'&name','dob','&course_id');

Page No: 15

SQL> insert into course20 values(&course_id,'&name',&fee,'&duration',&status); SQL> SELECT * FROM STUDENT20; ROLL_NO ---------100 101 116 103 105 106 107 108 109 110 111 112 DOB COURSE_ID NAME --------- ---------- -------------------20-JAN-88 1313 RAMESH 13-JUN-02 1314 SUKUMAR 14-JAN-88 1311 HANMANTHU 13-APR-78 1000 SURESH 24-JAN-03 1315 TEJA 13-JAN-87 1313 RAMESH 1313 RAJESH 1313 ANIL 1313 SHIVA 1313 SURYA 1313 RAM 1313 HAREESH

12 rows selected. SQL> SELECT* FROM COURSE20; COURSE_ID ---------1313 1314 1315 1316 1312 1311 1000 NAME FEE DURATION Status -------------------- ---------- -------------------MCA 25000 3 offered B.Sc. 10000 3 offered M.P.Cs. 15000 3 offered B.COM. 8000 2 offered MBA 28000 2 offered M.TECH. 50000 2 offered Ph.D 90000 5 offered

Sql> select s.name from student20 s,course20 c where s.course_id=c.course_id and c.name like 'MCA' and round((sysdate-dob)/365)>18; NAME -------------------RAMESH RAMESH RAJESH ANIL SHIVA SURYA RAM HAREESH 8 rows selected. SQL> select name from course20 where fee>(select fee from course20 where name like 'MCA'); NAME -------------------MBA M.TECH. Ph.D

6.

Create the following table : Page No: 16

Student (roll-no, name, subject-name, subject-opted) Subject(faculty-code, faculty-name, specialization) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) Find the number of students who have enrolled for the subject "DBMS". (ii) Find all those faculty members who have not offered any subject.
sql> create table student(roll_no number(5) primary key,name varcharr2(20),subject_name varchar2(20),subject_opted varchar2(10)); Table created Sql> create table subject(faculty_code number(5) primary key,faculty_name varchar2(20),specialization varchar2(10)); Table created

Page No: 17

Sql> insert into student values(&roll_no,&name,&subject_name,&subject_opted); Sql> insert into subject values(&faculty_code,&faculty_name,&specialization);

SQL> select count(name) from student st,subject_rank sb where st.subject_code=sb.subject_code and sb.subject_name like 'DBMS'; COUNT(NAME) ----------1 Sql> select faculty_name from faculty where faculty_code in(select faculty_code from faculty minus select faculty_code from subject_rank); No rows selected

Page No: 18

7.

Create the following table : Item (item-code, item-name, qty-in-stock, reorder-level) Supplier (supplier-code, supplier-name, address) Can_supply(supplier-code, item-code) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) List all those suppliers who can supply the given item. (ii) List all those items which cannot be supplied by given company.
Sql> create table item(item_code number(5)primary key,item_name varchar2(20),qty_in_stock number(3),reorder_level number(3)); Table created. Sql> create table supplier(supplier_code number(5)primary key,supplier_name varchar2(20),address varchar2(20)); Table created. Sql> create table can_supply(supplier_code number(5)references supplier(supplier_code),item_code number(5)references item(item_code));
Table created.

Page No: 19

Page No: 20

Page No: 21

Sql> insert into item values(&item_code,&item_name,&qty_in_stock,&reorder_level); Sql> insert into supplier values(&supplier_code,&supplier_name,&address); Sql> insert into can_supply values(&supplier_code,&item_code); Sql> select supplier_name from item i , supplier s,can_supply c where i.item_code=c.item_code and s.supplier_code=c.supplier_code and i.item_name like &item_name; Sql> select item_name from item i,supplier s,can_supply c where i.item_code=c.item_code and s.supplier_code=c.supplier_code and s.supplier_name not like &company_name;

Page No: 22

8.

Create the following tables: Student24 (roll-no, marks, category, district, state) Student-rank24(roll-no, marks, rank) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) List all those students who have come from Tamilnadu state and secured a rank above 100. (ii) List all those students who come from Andhra Pradesh state and belong to given category who have secured a rank above 100.
Sql> create table student24(roll_no number(4),name varchar2(20),category varchar2(10),district varchar2(20),state varchar2(20)) Table created SQL> create table student_rank24(roll_no number(4)references student24(roll_no),marks number(4),rank number(5)); Table created.

Page No: 23

Page No: 24

SQL> insert into student24 values(&roll_no,'&name','&category','&district'); SQL> insert into student_rank24 values(&roll_no,&marks,&rank); SQL> select* from student24; ROLL_NO ---------100 102 103 101 104 121 125 NAME -------------------Ramesh sIVA KUMAR RAJU KUMAR TEJA SUKUMAR CATEGORY ---------OC BC.A OC OC OC BC.B OC DISTRICT -------------------ADILABAD WARANGAL GUNTUR CHITTOOR PRAKASAM VELLOR VELLOR STATE -----AP AP AP AP AP TAMILNADU TAMILNADU

Sql>insert into student_rank24 values(&roll_no,&marks,&rank); SQL> SELECT* FROM STUDENT_RANK24; ROLL_NO MARKS RANK ---------- ---------- ---------100 125 5 101 148 2 104 146 3 103 149 1 102 135 4 107 124 6 108 115 7 109 115 8 110 114 9 121 100 11 125 105 10 sql> select name from student24 s,student_rank24 r where s.roll_no=r.roll_no and rank>10 and state like 'TAMILNADU'; NAME -------------------TEJA SQL> select name from student24 s,student_rank24 r where s.roll_no=r.roll_no and rank>5 and state like 'AP' and category like 'OC'; NAME -------------------RAJU kumar RAJESH TEJA SURESH

Page No: 25

9.

Create the following tables : Branch (branch-id, branch-name, customer-city, branch-id) Customer (customer-id, customer-name, customer-city, branch-id) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) List all those customers who live in the same city as the branch in which they have account. (ii) List all those customers who have an account in a given branch city.

Sql> create table branch(branch_id number(5),branch_name varchar2(20),customer_city varchar2(20)); Table created. Sql> create table customer(customer_id number(5),customer_name varchar2(20),customer_city varchar2(20),branch_id number(5)references branch(branch_id); Table created.

Sql> insert into branch_values(&branch_id,&branch_name,&customer_city); Sql> insert into customer values(&customer_id,&customer_sname,&customer_city,&branch_id);


SQL> SELECT* FROM BRANCH; BRANCH_ID ---------1 115 101 225 226 229 103 104 106 119 120 BRANCH_NAME -------------------SAIDABAD KAVADIGUDA NALLAKUNTA KAMBAN STREET KASTURIBA NAGAR PARK TOWN VIDYANAGAR SHIVAM ROAD RAMNAGAR SECUNDERABAD NAMPALLI BRANCH_CITY -------------------HYDERABAD HYDERABAD HYDERABAD CHENNAI CHENNAI CHENNAI HYDERABAD HYDERABAD HYDERABAD HYDERABAD HYDERABAD

Page No: 26

SQL> SELECT * FROM CUSTOMER; CUSTOMER_ID ----------1313 1314 1314 1314 1315 1316 1317 1318 1319 CUSTOMER_NAME -------------------RAJESH SIVA SIVA SIVA BRAMAR RAJESH SIVA RAMESH SRINU CUSTOMER_CITY BRANCH_ID -------------------- ---------HYDERABAD 103 CHENNAI 229 CHENNAI 119 CHENNAI 101 HYDERABAD 101 HYDERABAD 101 RAJASTHAN 101 CHENNAI 101 HYDERABAD 101

Sql> select customer_name from customer c,branch b where b.branch_id=c.branch_id and b.branch_city=c.customer_city; Sql> select customer_name from customer c,branch b where b.branch_id=c.branch_id and branch_city=&branch_city;

Page No: 27

10.

Create the following tables : Book10(accession-no, title, publisher, year, date-of-purchase, status) Member10(member-id, name, number-of-books-issued, max-limit) Book-issued(accession-no, member-id, date-of-issue) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) List all those books which are due from the students to be returned. A book is considered to be due if it has been issued 15 days back and yet not returned. (ii) List all those members who cannot be issued any more books.
Sql> create table book10(accession_no number(5),title varchar2(20),publisher varchar2(30),author varchar2(20),status varchar2(20),dop date); Table created SQL> create table member10(member_id number(4)primary key,name varchar2(20),nobi number(1),max_limit number(1)); Table created. SQL> create table book_issued(accession_no number(5) references book10(accession_no),member_id number(5) references member10(member_id),doi date); Table created.

Page No: 28

SQL> insert into book10 values(&accession_no,'&title','&publisher',&year,'&dop','&status'); SQL> insert into member10 values(&member_id,'&name',&nob,&max_limit); SQL> SELECT* FROM MEMBER10; MEMBER_ID ---------1313 1314 1316 1315 1317 1318 1319 NAME NOBI MAX_LIMIT -------------------- ---------- ---------RAJESH 2 5 SIVA 1 5 RAMESH 3 5 RAJKUMARY 5 5 SRI 0 5 SURESH 4 5 RAJU

SQL> insert into book_issued values(&accession_no,&member_id,'&doi'); SqL> select* from book10;


ACCESSION_NO -----------100 101 102 103 105 104 106 107 TITLE PUBLISHER YEAR DOP STATUS ------------------------ -------------------- ---------- --------- ------SE TATA MC HILL 1999 12-JAN-99 ISSUED OR S.CHAND 2005 15-JUN-05 ISSUED DAA TATA MC HILL 1088 NOT ISSUED DAA TATA MC HILL 2005 13-JAN-04 ISSUED SE TATA MC HILL 2003 13-JAN-02 ISSUED OR S.CHAND 1988 ISSUED OR S.CHAND 2005 ISSUED SE TATA MC HILL 1999 14-AUG-98 ISSUED

Sql> insert into book_issued values(&accession_no,&member_id,'&doi'); SQL> SELECT* FROM BOOK_ISSUED; ACCESSION_NO MEMBER_ID DOI ------------ ---------- --------100 1315 12-JUN-03 101 1314 10-JUN-03 102 1315 12-MAR-04 103 1315 10-SEP-01 107 1315 101 1315 105 1313 106 1313 104 1313 SQL> select title from book10 b,book_issued i where b.accession_no=i.accession_no and (sysdate-doi)>15; TITLE -------------------SE OR DAA DAA SQL> select name from member10 where nobi=max_limit; NAME -------------------RAJKUMARY

Page No: 29

11.

Create the following tables : Book(accession-no, title, publisher, year, date-of-purchase, status) Member(member-id, name, number-of-books-issued, max-limit) Book-issue(accession-no, member-id, date-of-issue) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Write a PL/SQL procedure to issue the book. Write a trigger to set the status of students to "back listed" if they have taken book but not returned even after one year.
Sql> create table book10(accession_no number(5),title varchar2(20),publisher varchar2(30),author varchar2(20),status varchar2(20),dop date); Table created SQL> create table member10(member_id number(4)primary key,name varchar2(20),nobi number(1),max_limit number(1)); Table created. SQL> create table book_issued(accession_no number(5) references book10(accession_no),member_id number(5) references member10(member_id),doi date); Table created.

Page No: 30

SQL> insert into book10 values(&accession_no,'&title','&publisher',&year,'&dop','&status'); SQL> insert into member10 values(&member_id,'&name',&nob,&max_limit); SQL> SELECT* FROM MEMBER10; MEMBER_ID ---------1313 1314 1316 1315 1317 1318 1319 NAME NOBI MAX_LIMIT -------------------- ---------- ---------RAJESH 2 5 SIVA 1 5 RAMESH 3 5 RAJKUMARY 5 5 SRI 0 5 SURESH 4 5 RAJU

SQL> insert into book_issued values(&accession_no,&member_id,'&doi'); SqL> select* from book10;


ACCESSION_NO -----------100 101 102 103 105 104 106 107

TITLE PUBLISHER YEAR DOP STATUS after insert on book_issued ------------------------ -------------------- ---------- --------- ------begin SE TATA MC HILL 1999 12-JAN-99 ISSUED update member10 set status='back listed' where ISSUED OR S.CHAND 2005 15-JUN-05 DAA 1088 member_id TATA MC HILL in(select SQL> insert into book10 NOT ISSUED DAA TATA MC HILL 2005 13-JAN-04 ISSUED values(&accession_no,'&title','&publisher',&ye SE TATA MC HILL 2003 13-JAN-02 ISSUED ar,'&dop','&status'); OR S.CHAND 1988 ISSUED OR S.CHAND 2005 ISSUED SE TATA MC HILL 1999 14-AUG-98 ISSUED

create or replace trigger blist

Sql> insert into book_issued values(&accession_no,&member_id,'&doi'); SQL> insert SQL> SELECT* FROM BOOK_ISSUED; into member10 values(&member_id,'&name',&nob,&max_limit); ACCESSION_NO MEMBER_ID DOI ------------ ---------- SELECT* FROM MEMBER10; SQL> --------100 1315 12-JUN-03 101 1314 10-JUN-03 MEMBER_ID NAME NOBI MAX_LIMIT 102 1315 12-MAR-04 103 1315 10-SEP-01 107 1315 101 1315 ---------- -------------------- ---------105 1313 106 ---------1313 104 1313 SQL> ed bramar11-1 2 create 1313 RAJESH or replace procedure back_listed(acc number,mid 5 number) is begin insert into book_issued values(acc,mid,sysdate); 1314 SIVA 1 update book10 set status='issued' where accession_no=acc; 5 update member10 set nobi=nobi+1 where member_id=mid; dbms_output.put_line('book issued'); end; 5 1316 RAMESH 3

Page No: 31 1315 RAJKUMARY


5

1317 SRI

SQL> @bramar11-1 9 / Procedure created.

1318 SURESH 5

SQL> exec back_listed(100,1314) 1319 RAJU PL/SQL procedure successfully completed. SQL> insert into book_issued values(&accession_no,&member_id,'&doi'); SQL> select * from member10; MEMBER_ID ---------1313 1314 1316 1315 1317 1318 NAME NOBI MAX_LIMIT -------------------- from book10; ---------- ---------SqL> select* RAJESH 2 5 SIVA 2 5 ACCESSION_NO TITLE PUBLISHER RAMESH 3 5 YEAR DOP STATUS RAJKUMARY 5 5 SRI 0 5 ------------ -----------------------SURESH -------------------- ---------- --------- ------4 5
100 SE 1999 12-JAN-99 ISSUED 101 OR 2005 15-JUN-05 ISSUED 102 DAA 1088 NOT ISSUED TATA MC HILL TATA MC HILL

SQL> ed bramar11-2;

S.CHAND

TATA MC HILL

103 DAA 2005 13-JAN-04 ISSUED 105 SE 2003 13-JAN-02 ISSUED 104 OR 1988 106 OR ISSUED

SQL> @bramar11-2 7 / Trigger created.

TATA MC HILL

S.CHAND

SQL> insert into book_issued values(100,1313,'15-aug-2007');


S.CHAND

1 row created.

2005 107 SE

ISSUED TATA MC HILL

1999 14-AUG-98 ISSUED SQL> select * from member10;

MEMBER_ID ---------1313 1314 1316 1315 1317 1318 1319

NAME NOBI MAX_LIMIT STATUS -------------------- ---------- ---------- -------------------RAJESH Sql> insert into book_issued 2 5 back listed SIVA 3 5 back values(&accession_no,&member_id,'&doi'); listed RAMESH SQL> SELECT* FROM BOOK_ISSUED; 3 5 RAJKUMARY 5 DOI 5 back listed ACCESSION_NO MEMBER_ID SRI 0 5 SURESH 4 5 RAJU 2 5 ------------ ---------- ---------

Page No: 32
100 1315 12-JUN-03

101

1314 10-JUN-03

12.

Create the following tables : Book10(accession-no, title, publisher, year, date-of-purchase, status) Book-Place(accession-no, rack-id, rack-position) 102 1315 12-MAR-04 Member10(member-id, name, number-of-books-issued, max-limit, status) Book_issued(accession-no, member-id, date-of-issue) (a) Create a form to accept the data from the user with appropriate validation 103 1315 10-SEP-01 checks. (b) Write a PL/SQL procedure to issue the book. Write a trigger to set the status of a book neither to "lost" which is neither 107 1315 issued nor in the library.
Sql> create table book10(accession_no number(5),title varchar2(20),publisher varchar2(30),author varchar2(20),status varchar2(20),dop date); Table created 101 1315 SQL> create table member10(member_id number(4)primary key,name varchar2(20),nobi number(1),max_limit number(1)); able created. Sql> create table book_place(accession_no number(4),rack_id number(2),rack_position number(3)); 105 1313 Table created. SQL> create table book_issued(accession_no number(5) references book10(accession_no),member_id number(5) references member10(member_id),doi 106 1313 date); Table created. 104 1313

member_id from book_issued where months_between(sysdate,doi)>12); end;

Page No: 33

SQL> insert into book10 values(&accession_no,'&title','&publisher',&year,'&dop','&status'); SQL> insert into member10 values(&member_id,'&name',&nob,&max_limit); SQL> SELECT* FROM MEMBER10; MEMBER_ID ---------1313 1314 1316 1315 1317 1318 1319 NAME NOBI MAX_LIMIT -------------------- ---------- ---------RAJESH 2 5 SIVA 1 5 RAMESH 3 5 RAJKUMARY 5 5 SRI 0 5 SURESH 4 5 RAJU

SQL> insert into book_issued values(&accession_no,&member_id,'&doi'); SqL> select* from book10;


ACCESSION_NO -----------100 101 102 103 105 104 106 107 TITLE PUBLISHER YEAR DOP STATUS ------------------------ -------------------- ---------- --------- ------SE TATA MC HILL 1999 12-JAN-99 ISSUED OR S.CHAND 2005 15-JUN-05 ISSUED DAA TATA MC HILL 1088 NOT ISSUED DAA TATA MC HILL 2005 13-JAN-04 ISSUED SE TATA MC HILL 2003 13-JAN-02 ISSUED OR S.CHAND 1988 ISSUED OR S.CHAND 2005 ISSUED SE TATA MC HILL 1999 14-AUG-98 ISSUED

Sql> insert into book_issued values(&accession_no,&member_id,'&doi'); SQL> SELECT* FROM BOOK_ISSUED; ACCESSION_NO MEMBER_ID DOI ------------ ---------- --------100 1315 12-JUN-03 101 1314 10-JUN-03 102 1315 12-MAR-04 103 1315 10-SEP-01 107 1315 101 1315 105 1313 106 1313 104 1313 Sql> insert into book_place values(accession_no number(5) primary key,rack_id number(2),rack_position number(2));
Sql> ed bramar12_1

Create or replace procedure lost(mid number,acc number) Is Begin Insert into book_issued values(acc,mid,sysdate); Update bok10 set nobi=nobi+1 where member_id mid; Delete frombook_place where acessionm_no=acc; Dbms_outpout.put_line(Book issued); End;

Sql> @bramar12_1

Page No: 34

10/ Procedure created. Sql> exec lost(1315,107); Book Issued. Sql> ed bramar12_2

Create or replace trigger lost after insert on book_issued Begtin Update book10 set status=lost where accession_no in(select accession_no from book10 minus(select accession_no from book_issued union select accession_no from book_place)); End;

Sql> @bramar12_2 8 / Trigger created. SQL> select * from book10;


ACCESSION_NO -----------100 101 102 103 105 104 106 107 TITLE PUBLISHER YEAR DOP STATUS ------------------------ -------------------- ---------- --------- ------SE TATA MC HILL 1999 12-JAN-99 ISSUED OR S.CHAND 2005 15-JUN-05 ISSUED DAA TATA MC HILL 1088 LOST DAA TATA MC HILL 2005 13-JAN-04 ISSUED SE TATA MC HILL 2003 13-JAN-02 ISSUED OR S.CHAND 1988 ISSUED OR S.CHAND 2005 ISSUED SE TATA MC HILL 1999 14-AUG-98 ISSUED

Page No: 35

13.

Create the following tables : Book10(accession-no, title, publisher, year, date-of-purchase, status) Member10(member-id, name, number-of-books-issued, max-limit, status) Book_issued(accession-no, member-id, date-of-issue, due-date) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Write a PL/SQL to list all those students who are defaulters. A student is considerer to be a defaulter if he has not returned a book even after due-date. Write a trigger to set the status of students to "back listed" if they have taken book but not returned even after one year.

Sql> create table book10(accession_no number(5),title varchar2(20),publisher varchar2(30),author varchar2(20),status varchar2(20),dop date); Table created SQL> create table member10(member_id number(4)primary key,name varchar2(20),nobi number(1),max_limit number(1)); Table created. SQL> create table book_issued(accession_no number(5) references book10(accession_no),member_id number(5) references member10(member_id),doi date); Table created.

Page No: 36

SQL> insert into book10 values(&accession_no,'&title','&publisher',&year,'&dop','&status'); SQL> insert into member10 values(&member_id,'&name',&nob,&max_limit); SQL> SELECT* FROM MEMBER10; MEMBER_ID ---------1313 1314 1316 1315 1317 1318 1319 NAME NOBI MAX_LIMIT -------------------- ---------- ---------RAJESH 2 5 SIVA 1 5 RAMESH 3 5 RAJKUMARY 5 5 SRI 0 5 SURESH 4 5 RAJU

SQL> insert into book_issued values(&accession_no,&member_id,'&doi'); SqL> select* from book10;


ACCESSION_NO -----------100 101 102 103 105 104 106 107 TITLE PUBLISHER YEAR DOP STATUS ------------------------ -------------------- ---------- --------- ------SE TATA MC HILL 1999 12-JAN-99 ISSUED OR S.CHAND 2005 15-JUN-05 ISSUED DAA TATA MC HILL 1088 NOT ISSUED DAA TATA MC HILL 2005 13-JAN-04 ISSUED SE TATA MC HILL 2003 13-JAN-02 ISSUED OR S.CHAND 1988 ISSUED OR S.CHAND 2005 ISSUED SE TATA MC HILL 1999 14-AUG-98 ISSUED

Sql> insert into book_issued values(&accession_no,&member_id,'&doi'); SQL> SELECT* FROM BOOK_ISSUED; ACCESSION_NO MEMBER_ID DOI ------------ ---------- --------100 1315 12-JUN-03 101 1314 10-JUN-03 102 1315 12-MAR-04 103 1315 10-SEP-01 107 1315 101 1315 105 1313 106 1313 SQL> ed bramar11-2;

create or replace trigger blist after insert on book_issued begin

update member10 set status='back listed' where member_id in(select SQL> insert into book10

values(&accession_no,'&title','&publisher',&year,'&d op','&status'); END;

Page No: 37

SQL> @bramar11-2 7 / Trigger created. SQL> insert into book_issued values(100,1313,'15-aug-2007'); 1 row created. SQL> select * from member10; MEMBER_ID ---------1313 1314 1316 1315 1317 1318 1319 NAME NOBI MAX_LIMIT STATUS -------------------- ---------- ---------- -------------------RAJESH 2 5 back listed SIVA 3 5 back listed RAMESH 3 5 RAJKUMARY 5 5 back listed SRI 0 5 SURESH 4 5 RAJU 2 5

Page No: 38

14.

Create the following tables : Branch (branch-id, branch-name, branch-city) Customer (customer-id, customer-name, customer-city, branch-id) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) List all those customers who live in the same city as the branch in which they have account. (ii) List all those customers who have an account in more than one branch.

Sql> create table branch(branch_id number(5),branch_name varchar2(20),customer_city varchar2(20)); Table created. Sql> create table customer(customer_id number(5),customer_name varchar2(20),customer_city varchar2(20),branch_id number(5)references branch(branch_id); Table created.
Sql> insert into branch_values(&branch_id,&branch_name,&customer_city); Sql> insert into customer values(&customer_id,&customer_sname,&customer_city,&branch_id);
SQL> SELECT* FROM BRANCH; BRANCH_ID ---------1 115 101 225 226 229 103 104 106 119 120 BRANCH_NAME -------------------SAIDABAD KAVADIGUDA NALLAKUNTA KAMBAN STREET KASTURIBA NAGAR PARK TOWN VIDYANAGAR SHIVAM ROAD RAMNAGAR SECUNDERABAD NAMPALLI BRANCH_CITY -------------------HYDERABAD HYDERABAD HYDERABAD CHENNAI CHENNAI CHENNAI HYDERABAD HYDERABAD HYDERABAD HYDERABAD HYDERABAD

SQL> SELECT * FROM CUSTOMER; CUSTOMER_ID ----------1313 1314 1314 1314 1315 1316 1317 1318 1319 CUSTOMER_NAME -------------------RAJESH SIVA SIVA SIVA BRAMAR RAJESH SIVA RAMESH SRINU CUSTOMER_CITY BRANCH_ID -------------------- ---------HYDERABAD 103 CHENNAI 229 CHENNAI 119 CHENNAI 101 HYDERABAD 101 HYDERABAD 101 RAJASTHAN 101 CHENNAI 101 HYDERABAD 101

Page No: 39

Sql> select customer_name from customer c, branch b where c.branch_id=b.,branch_id and branch_city=customer_city; Sql> select customer_name from customer c1,customer c2 where c1.customer_id=c2.customer_id and c1.branch_id!=c2.branch_id;

Page No: 40

15.

Create the following tables : Branch (branch-id, branch-name, customer-city) Customer (customer-id, customer-name, customer-city, branch-id) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) List all those customers who have more than 100 customer. (ii) List all those customers who have an account in more than one branch.

Sql> create table branch(branch_id number(5),branch_name varchar2(20),customer_city varchar2(20)); Table created. Sql> create table customer(customer_id number(5),customer_name varchar2(20),customer_city varchar2(20),branch_id number(5)references branch(branch_id); Table created.
Sql> insert into branch_values(&branch_id,&branch_name,&customer_city); Sql> insert into customer values(&customer_id,&customer_sname,&customer_city,&branch_id);
SQL> SELECT* FROM BRANCH; BRANCH_ID ---------1 115 101 225 226 229 103 104 106 119 120 SQL> SELECT CUSTOMER_ID ----------1313 1314 1314 1314 1315 1316 1317 1318 1319 BRANCH_NAME -------------------SAIDABAD KAVADIGUDA NALLAKUNTA KAMBAN STREET KASTURIBA NAGAR PARK TOWN VIDYANAGAR SHIVAM ROAD RAMNAGAR SECUNDERABAD NAMPALLI * FROM CUSTOMER; CUSTOMER_NAME -------------------RAJESH SIVA SIVA SIVA BRAMAR RAJESH SIVA RAMESH SRINU BRANCH_CITY -------------------HYDERABAD HYDERABAD HYDERABAD CHENNAI CHENNAI CHENNAI HYDERABAD HYDERABAD HYDERABAD HYDERABAD HYDERABAD CUSTOMER_CITY BRANCH_ID -------------------- ---------HYDERABAD 103 CHENNAI 229 CHENNAI 119 CHENNAI 101 HYDERABAD 101 HYDERABAD 101 RAJASTHAN 101 CHENNAI 101 HYDERABAD 101

Page No: 41

Sql> select branch_name from branch where branach_id in(select branch_id fromf customer grouoop by branch_id having count(*)>100; Sql> select customer_name from customer c1,customer c2 where c1.customer_id=c2.customer_id and jc1.branch_id!=c2.branch_id;

Page No: 42

16.

Create the following table : Student24 (roll-no, name, category, district, state) Student _rank 24(roll-no, marks, rank) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) List names of the students who are having same rank but they should reside in different districts. (ii) List details of students they belongs to same category with same rank.

Sql> create table student24(roll_no number(4) primary key,name varchar2(20),category varchar2(10),district varchar2(20),state varchar2(20)); Table created.
SQL> create table student_rank24(roll_no number(4)references student24(roll_no),marks number(4),rank number(5)); Table created.

Page No: 43

Page No: 44

SQL> insert into student24 values(&roll_no,'&name','&category','&district'); SQL> insert into student_rank24 values(&roll_no,&marks,&rank); SQL> SELECT* FROM STUDENT24; ROLL_NO NAME ---------- --------------------------------------100 Ramesh 102 sIVA 103 KUMAR 101 RAJU 104 KUMAR 121 TEJA 125 SUKUMAR 107 kumar 108 RAJESH 109 TEJA 110 SURESH CATEGORY DISTRICT STATE ---------- -------------------OC BC.A OC OC OC BC.B OC OC OC OC OC ADILABAD WARANGAL GUNTUR CHITTOOR PRAKASAM VELLOR VELLOR WARANGAL WARANGAL WARANGAL WARANGAL AP AP AP AP AP TAMILNADU TAMILNADU AP AP AP AP

SQL> SELECT* FROM STUDENT_RANK24; ROLL_NO MARKS RANK ---------- ---------- ---------100 125 5 101 148 2 104 146 3 103 149 1 102 135 4 107 124 6 108 115 7 109 115 8 110 114 9 121 100 11 125 105 10

SQL> select s.name from student24 s,student_rank24 r where s.roll_no=r.roll_no and rank in(select rank from student24 s1,student_rank24 r1 where s1.roll_no=r1.roll_no and s.district!=s1.district and s.roll_no! =s1.roll_no); NAME -------------------RAJU kumar Sql> select s.roll_no,s.name,category,district,state from student24 s,student_rank24 r where s.roll_no=r.roll_no and rank in(select rank from student24 s1,student_rank24 r1 where s1.roll_no=r1.roll_no and s.category=s1.category and s.roll_no!=s1.roll_no) ROLL_NO ---------101 107 NAME -------------------RAJU kumar CATEGORY ---------OC OC DISTRICT -------------------CHITTOOR WARANGAL STATE --------AP AP

Page No: 45

17.

Create the following tables : Student20(roll-no, name, date-of-birth, course-id) Course20 (Course-id, name, fee, duration) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) List all those students who are between 18-19 years of age and have opted for MCA course. (ii) List all those courses in which number of students are less than 10.

SQL> create table student20(roll_no number(4)primary key,dob date,course_id number(6)); Table created. Sql> create table course20(course_id number(6)primary key,name varchar2(20),fee number(5),duration varchar2(20)); Table created.

Page No: 46

SQL> insert into student20 values(&roll_no,'&name','dob','&course_id'); insert into course20 values(&course_id,'&name',&fee,'&duration') SQL> SELECT * FROM COURSE20; COURSE_ID ---------1313 1314 1315 1316 1312 1311 1000 NAME FEE DURATION -------------------- ---------- -------------------MCA 25000 3 B.Sc. 10000 3 M.P.Cs. 15000 3 B.COM. 8000 2 MBA 28000 2 M.TECH. 50000 2 Ph.D 90000 5

Page No: 47

SQL> select* from student20; ROLL_NO ---------100 101 116 103 105 106 107 108 109 110 111 112 DOB COURSE_ID NAME --------- ---------- -------------------20-JAN-88 1313 RAMESH 13-JUN-02 1314 SUKUMAR 14-JAN-88 1311 HANMANTHU 13-APR-78 1000 SURESH 24-JAN-03 1315 TEJA 13-JAN-87 1313 RAMESH 1313 RAJESH 1313 ANIL 1313 SHIVA 1313 SURYA 1313 RAM 1313 HAREESH

SQL> select s.roll_no,s.name from student20 s,course20 c where (sysdatedob)/365 between 18 and 19 and c.name='MCA' and s.course_id=c.course_id; No rows selected. For example: SQL> select s.roll_no,s.name from student20 s,course20 c where (sysdatedob)/365 between 15 and 25 and c.name='MCA' and s.course_id=c.course_id; ROLL_NO ---------100 106 107 108 109 110 111 112 NAME -------------------RAMESH RAMESH RAJESH ANIL SHIVA SURYA RAM HAREESH

SQL> select name from course20 where (select count(roll_no) from student20 s,course20 c where s.course_id=c.course_id)<10; no rows selected For example: SQL> select name from course20 where (select count(roll_no) from student20 s,course20 c where s.course_id=c.course_id)>3; NAME -------------------MCA B.Sc. M.P.Cs. B.COM. MBA M.TECH.
Ph.D

Page No: 48

18.

Create the following tables :

Student20(roll-no, name, date-of-birth, course-id) Course20 (Course-id, name, fee, duration, status) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Write PL/SQL procedure to do the following : Set the status of course to "not offered" in which the number of candidates is less than 5.
SQL> create table student20(roll_no number(4)primary key,dob date,course_id number(6)); Table created. Sql> create table course20(course_id number(6)primary key,name varchar2(20),fee number(5),duration varchar2(20)); Table created.

Page No: 49

SQL> insert into student20 values(&roll_no,'&name','dob','&course_id'); insert into course20 values(&course_id,'&name',&fee,'&duration') SQL> SELECT * FROM COURSE20; COURSE_ID ---------1313 1314 1315 1316 1312 1311 1000 NAME FEE DURATION -------------------- ---------- -------------------MCA 25000 3 B.Sc. 10000 3 M.P.Cs. 15000 3 B.COM. 8000 2 MBA 28000 2 M.TECH. 50000 2 Ph.D 90000 5

Page No: 50

SQL> select* from student20; ROLL_NO ---------100 101 116 103 105 106 107 108 109 110 111 112 DOB COURSE_ID NAME --------- ---------- -------------------20-JAN-88 1313 RAMESH 13-JUN-02 1314 SUKUMAR 14-JAN-88 1311 HANMANTHU 13-APR-78 1000 SURESH 24-JAN-03 1315 TEJA 13-JAN-87 1313 RAMESH 1313 RAJESH 1313 ANIL 1313 SHIVA 1313 SURYA 1313 RAM 1313 HAREESH

SQL> ed bramar19

create or replace procedure not_offered5(sname varchar2) is c number; begin select count(name) into c from student where name=sname; if c<5 then update student set status='not offered' where name=sname; end if; end;
SQL> @bramar19 8 / Procedure created. SQL> exec not_offered PL/SQL procedure successfully completed. SQL> select* from course20; COURSE_ID ---------1313 1314 1315 1316 1312 1311 1000 NAME FEE DURATION -------------------- ---------- -------------------MCA 25000 3 B.Sc. 10000 3 M.P.Cs. 15000 3 B.COM. 8000 2 MBA 28000 2 M.TECH. 50000 2 Ph.D 90000 5 STATUS ----------------offered offered offered offered offered offered offered

Page No: 51

20.

Create the following tables : Student20(roll-no, name, date-of-birth, course-id) Course20 (Course-id, name, fee, duration, status) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Write PL/SQL procedure to do the following : Set the status of course to "offered" in which the number of candidates is at least 10 otherwise set it to "not offered".

SQL> create table student20(roll_no number(4)primary key,dob date,course_id number(6)); Table created. Sql> create table course20(course_id number(6)primary key,name varchar2(20),fee number(5),duration varchar2(20)); Table created.

Page No: 52

SQL> insert into student20 values(&roll_no,'&name','dob','&course_id'); insert into course20 values(&course_id,'&name',&fee,'&duration') SQL> SELECT * FROM COURSE20; COURSE_ID ---------1313 1314 1315 1316 1312 1311 1000 NAME FEE DURATION -------------------- ---------- -------------------MCA 25000 3 B.Sc. 10000 3 M.P.Cs. 15000 3 B.COM. 8000 2 MBA 28000 2 M.TECH. 50000 2 Ph.D 90000 5

Page No: 53

SQL> select* from student20; ROLL_NO ---------100 101 116 103 105 106 107 108 109 110 111 112 DOB COURSE_ID NAME --------- ---------- -------------------20-JAN-88 1313 RAMESH 13-JUN-02 1314 SUKUMAR 14-JAN-88 1311 HANMANTHU 13-APR-78 1000 SURESH 24-JAN-03 1315 TEJA 13-JAN-87 1313 RAMESH 1313 RAJESH 1313 ANIL 1313 SHIVA 1313 SURYA 1313 RAM 1313 HAREESH

Sql> ed bramar20

create or replace procedure offered is begin update course20 set status='offered' where 3<(select count(roll_no) from student20 s,course20 c where s.course_id=c.course_id); update course20 set status='not offered' where 3>(select count(roll_no) from student20 s,course20 c where s.course_id=c.course_id); end;

SQL> @bramar20 9 / Procedure created. SQL> exec offered PL/SQL procedure successfully completed. SQL> select* from course20; COURSE_ID ---------1313 1314 1315 1316 1312 1311 1000 NAME FEE DURATION -------------------- ---------- -------------------MCA 25000 3 B.Sc. 10000 3 M.P.Cs. 15000 3 B.COM. 8000 2 MBA 28000 2 M.TECH. 50000 2 Ph.D 90000 5 STATUS ---------------offered offered offered offered offered offered offered

Page No: 54

21.

Create the following table : Item (item-code, item-name, qty-in-stock, reorder-level) Supplier (supplier-code, supplier-name, address) Can-supply(supplier-code, item-code) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Write PL/SQL procedure to do the following : Generate a report to list the items whose qty-in-stock is less than or equal to their reorder-levels.

Sql> create table item(item_code number(5)primary key,item_name varchar2(20),qty_in_stock number(3),reorder_level number(3)); Table created. Sql> create table supplier(supplier_code number(5)primary key,supplier_name varchar2(20),address varchar2(20)); Table created. Sql> create table can_supply(supplier_code number(5)references supplier(supplier_code),item_code number(5)references item(item_code));
Table created.

Page No: 55

Page No: 56

Page No: 57

Sql> insert into item values(&item_code,&item_name,&qty_in_stock,&reorder_level); Sql> insert into supplier values(&supplier_code,&supplier_name,&address); Sql> insert into can_supply values(&supplier_code,&item_code); SQL> select* from item; ITEM_CODE ---------1000 1001 1002 1003 1004 1005 1006 ITEM_NAME QTY_IN_STOCK RECORD_LEVEL -------------------- ------------ -----------CHAIR 20 10 TABLE 15 5 COMPUTER 35 40 MONITOR 20 25 CPU 50 20 KEYBOARD 50 100 MOUSE 50 50

SQL> SELECT* FROM SUPPLIER; SUPPLIER_CODE SUPPLLIER_NAME ------------- -------------------100 RAJESH 101 SIVA 102 RAMU 103 KRISHNA 104 RAMESH 105 SATYA 106 TEJA SQL> select* from can_supply; SUPPLIER_CODE ITEM_CODE ------------- ---------101 1001 103 1005 102 1004 100 1005 100 1002 100 1006 100 1002 102 1005 103 1004 103 1004 101 1004 Sql> ed bramar21 ADDRESS -------------------KHAIRATHABAD,HYD AMEERPER,HYD AMEERPET,HYD SAIDABAD,HYD SAIDABAD,HYD RAMNAGAR,HYD NALLAKUNTA STATUS -------------------IMPORTANT IMPORTANT UNIMPORTANT UNIMPORTANT IMPORTANT IMPORTANT

Create or replace procedure item Is Begin Select item_name from item where qty_in_stock<reorder_level; End;

Page No: 58

Sql> @bramar21
7/ Procedure created. Sql>exec item Procedure successfully executed. ITEM_NAME --------------------------COMPUTER MONITOR KEYBOARD

Page No: 59

22.

Create the following table : Item (item-code, item-name, qty-in-stock, reorder-level) Supplier (supplier-code, supplier-name, address, status) Can-supply(supplier-code, item-code) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Write PL/SQL procedure to do the following : Set the status of the supplier to "important" if the supplier can supply more than five items.

Sql> create table item(item_code number(5)primary key,item_name varchar2(20),qty_in_stock number(3),reorder_level number(3)); Table created. Sql> create table supplier(supplier_code number(5)primary key,supplier_name varchar2(20),address varchar2(20)); Table created. Sql> create table can_supply(supplier_code number(5)references supplier(supplier_code),item_code number(5)references item(item_code));
Table created.

Page No: 60

Page No: 61

Page No: 62

Sql> insert into item values(&item_code,&item_name,&qty_in_stock,&reorder_level); Sql> insert into supplier values(&supplier_code,&supplier_name,&address); Sql> insert into can_supply values(&supplier_code,&item_code); SQL> select* from item; ITEM_CODE ---------1000 1001 1002 1003 1004 1005 1006 ITEM_NAME QTY_IN_STOCK RECORD_LEVEL -------------------- ------------ -----------CHAIR 20 10 TABLE 15 5 COMPUTER 35 40 MONITOR 20 25 CPU 50 20 KEYBOARD 50 100 MOUSE 50 50

SQL> SELECT* FROM SUPPLIER; SUPPLIER_CODE SUPPLLIER_NAME ------------- -------------------100 RAJESH 101 SIVA 102 RAMU 103 KRISHNA 104 RAMESH 105 SATYA 106 TEJA SQL> select* from can_supply; SUPPLIER_CODE ITEM_CODE ------------- ---------101 1001 103 1005 102 1004 100 1005 100 1002 100 1006 100 1002 102 1005 103 1004 103 1004 101 1004 100 1003 100 1000 ADDRESS -------------------KHAIRATHABAD,HYD AMEERPER,HYD AMEERPET,HYD SAIDABAD,HYD SAIDABAD,HYD RAMNAGAR,HYD NALLAKUNTA STATUS -------------------UNIMPORTANT IMPORTANT UNIMPORTANT UNIMPORTANT IMPORTANT IMPORTANT

Page No: 63

Sql> ed bramar23

Create or replace procedure proc22 Is Begin Update supplier set status=important where supplier_code in(select supplier_code from supplier s where 5<=(select count(item_code) from can_supply c where s.suplier_code=c.supplier_code)); End;
Sql> @bramar23 9/ Procedure created. Sql> exec item Procedure executed successfully. SQL> SELECT* FROM SUPPLIER; SUPPLIER_CODE ------------100 101 102 103 104 105 106 SUPPLLIER_NAME -------------------RAJESH SIVA RAMU KRISHNA RAMESH SATYA TEJA ADDRESS -------------------KHAIRATHABAD,HYD AMEERPER,HYD AMEERPET,HYD SAIDABAD,HYD SAIDABAD,HYD RAMNAGAR,HYD NALLAKUNTA STATUS -------------------IMPORTANT IMPORTANT UNIMPORTANT UNIMPORTANT IMPORTANT IMPORTANT

Page No: 64

23.

Create the following tables : Item (item-code, item-name, qty-in-stock, reorder-level) Supplier (supplier-code, supplier-name, address, status) Can-supply(supplier-code, item-code) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Write PL/SQL procedure to do the following : Generate a report of those items that are supplied by those suppliers whose status is "important".

Sql> create table item(item_code number(5)primary key,item_name varchar2(20),qty_in_stock number(3),reorder_level number(3)); Table created. Sql> create table supplier(supplier_code number(5)primary key,supplier_name varchar2(20),address varchar2(20)); Table created. Sql> create table can_supply(supplier_code number(5)references supplier(supplier_code),item_code number(5)references item(item_code));
Table created.

Page No: 65

Page No: 66

Page No: 67

Sql> insert into item values(&item_code,&item_name,&qty_in_stock,&reorder_level); Sql> insert into supplier values(&supplier_code,&supplier_name,&address); Sql> insert into can_supply values(&supplier_code,&item_code); SQL> select* from item; ITEM_CODE ---------1000 1001 1002 1003 1004 1005 1006 ITEM_NAME QTY_IN_STOCK RECORD_LEVEL -------------------- ------------ -----------CHAIR 20 10 TABLE 15 5 COMPUTER 35 40 MONITOR 20 25 CPU 50 20 KEYBOARD 50 100 MOUSE 50 50

SQL> SELECT* FROM SUPPLIER; SUPPLIER_CODE SUPPLLIER_NAME ------------- -------------------100 RAJESH 101 SIVA 102 RAMU 103 KRISHNA 104 RAMESH 105 SATYA 106 TEJA SQL> select* from can_supply; SUPPLIER_CODE ITEM_CODE ------------- ---------101 1001 103 1005 102 1004 100 1005 100 1002 100 1006 100 1002 102 1005 103 1004 103 1004 101 1004 100 1003 100 1000 ADDRESS -------------------KHAIRATHABAD,HYD AMEERPER,HYD AMEERPET,HYD SAIDABAD,HYD SAIDABAD,HYD RAMNAGAR,HYD NALLAKUNTA STATUS -------------------UNIMPORTANT IMPORTANT UNIMPORTANT UNIMPORTANT IMPORTANT IMPORTANT

Page No: 68

Sql> ed bramar23

create or replace procedure imp is cursor c1 is select i.item_name from supplier s,item i,can_supply c where s.supplier_code=c.supplier_code and i.item_code=c.item_code and s.status like 'important'; begin for r in c1 loop dbms_output.put_line(r.item_name); end loop; end;

Sql> @bramar23 12 / Procedure created. Sql> exec imp Procedure successfully executed.

Page No: 69

24.

Create the following tables : Student24 (roll-no, name, category, district, state) Student rank24 (roll-no, marks, rank) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Write PL/SQL procedure to the following : Generate a report to list of those districts from which the first hundred rankers come from.

Sql> create table student24(roll_no number(4) primary key,name varchar2(20),category varchar2(10),district varchar2(20),state varchar2(20)); Table created.
SQL> create table student_rank24(roll_no number(4)references student24(roll_no),marks number(4),rank number(5)); Table created.

Page No: 70

SQL> ed bramar24

create or replace procedure dranker(dname varchar2) is cursor c1 is select s.roll_no,s.name,s.category,s.state,sr.marks,sr.rank from student24 s,student_rank24 sr where s.roll_no=sr.roll_no and s.district=dname order by rank; begin for r in c1 loop if c1%rowcount<=100 then dbms_output.put_line(r.roll_no||' '||r.name||' '||r.category||' '||r.marks||' '|| r.rank); end if; end loop; end;
SQL> @bramar24 13 / Procedure created. SQL> exec dranker('WARANGAL'); 102 sIVA BC.A 135 4 107 kumar OC 124 6 108 RAJESH OC 115 7 109 TEJA OC 115 8 110 SURESH OC 114 9 PL/SQL procedure successfully completed.

Page No: 71

25.

Create the following tables : Student (roll-no, name, subject-opted) Subject rank (subject-code, subject-name, faculty-code, specialization) Faculty (faculty-code, faculty-name, specialization) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Write PL/SQL procedure to the following : Set the status of the subject to "not offered" if the subject is not opted by at least 5 students.

Sql> create table student(roll_no number(5) primary key,name varchar2(20),subject_opted varchar2(10)); Sql> create table faculty(faculty_code number(4)primary key,faculty_name varchar2(20), specialization varchar2(20)); Sql> create table subject_rank(subject_code number(4) primary key, subject_name varchar2(20), faculty_code number(4) references faculty(faculty_code));

Page No: 72

Sql> insert into subject_rank values(&subject_code,'&subject_name',&faculty_code); SQL> insert into faculty values(&faculty_code,'&faculty_name','&specialization'); Sql> insert into student values(&roll_no,'&name','&subject_opted',&subject_code);

SQL> select* from student; ROLL_NO NAME SUBJECT_OPTED SUBJECT_CODE ---------- -------------------- -------------------- -----------101 Anil DBMS 1313 102 RAJU SE 1315 103 DURGA OR 1314 104 BRAMAR OS 1316 105 SRIKANTH DAA 1317 SQL> select* from subject_rank; SUBJECT_CODE SUBJECT_NAME ------------ -------------------- -----------1313 DBMS 1000 FACULTY_CODE

Page No: 73

1314 OR 1315 SE 1316 OS 1317 DAA SQL> select* from faculty;

1001 1002 1003 1004

FACULTY_CODE FACULTY_NAME SPECIALIZATION ------------ -------------------- ------------------------------------------------------------1000 Ramesh M.TECH 1003 SIVA MCA 1002 RAJU M.Sc. 1004 RAJESH M.TECH 1001 KRISHNA M.Sc.

Sql> ed not_offered25

create or replace procedure not_offered5(sname varchar2) is c number; begin select count(name) into c from student where name=sname; if c<5 then update student set status='not offered' where name=sname; end if; end;

SQL> @not_offered25 10 / Procedure created. SQL> exec not_offered PL/SQL procedure successfully completed. SQL> select* from subject_rank; SUBJECT_CODE -----------1313 1314 1315 1316 1317 1318 SUBJECT_NAME FACULTY_CODE STATUS -------------------- ------------ -------------------DBMS 1000 offered OR 1001 offered SE 1002 offered OS 1003 offered DAA 1004 offered JAVA not offered

6 rows selected.

Page No: 74

26.

Create the following tables : Student (roll-no, name, subject-opted) Subject rank (subject-code, subject-name, faculty-code, specialization) Faculty (faculty-code, faculty-name, specialization) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Write PL/SQL procedure to the following : Set the status of the subject to "not offered" if the subject is not offered by any of the faculty members.

Sql> create table student(roll_no number(5) primary key,name varchar2(20),subject_opted varchar2(10)); Sql> create table faculty(faculty_code number(4)primary key,faculty_name varchar2(20), specialization varchar2(20)); Sql> create table subject_rank(subject_code number(4) primary key, subject_name varchar2(20), faculty_code number(4) references faculty(faculty_code));

Page No: 75

Sql> insert into subject_rank values(&subject_code,'&subject_name',&faculty_code); SQL> insert into faculty values(&faculty_code,'&faculty_name','&specialization'); Sql> insert into student values(&roll_no,'&name','&subject_opted',&subject_code);

SQL> select* from student; ROLL_NO NAME SUBJECT_OPTED SUBJECT_CODE ---------- -------------------- -------------------- -----------101 Anil DBMS 1313 102 RAJU SE 1315 103 DURGA OR 1314 104 BRAMAR OS 1316 105 SRIKANTH DAA 1317 SQL> select* from subject_rank; SUBJECT_CODE SUBJECT_NAME ------------ -------------------- -----------1313 DBMS 1000 1314 OR 1001 1315 SE 1002 1316 OS 1003 1317 DAA 1004 FACULTY_CODE

Page No: 76

SQL> select* from faculty; FACULTY_CODE FACULTY_NAME SPECIALIZATION ------------ -------------------- ------------------------------------------------------------1000 Ramesh M.TECH 1003 SIVA MCA 1002 RAJU M.Sc. 1004 RAJESH M.TECH 1001 KRISHNA M.Sc.

Sql> ed bramar26

create or replace procedure not_offered is begin update subject_rank set status='not offered' where faculty_code is NULL; end;
Sql> @bramar26 7/ Procedure created. SQL> exec not_offered PL/SQL procedure successfully completed. SQL> insert into subject_rank values(1318,'JAVA',NULL,'offered'); 1 row created. SQL> select* from subject_rank; SUBJECT_CODE SUBJECT_NAME FACULTY_CODE STATUS ------------ -------------------- ------------ --------------------------------------------------------------1313 DBMS 1000 offered 1314 OR 1001 offered 1315 SE 1002 offered 1316 OS 1003 offered 1317 DAA 1004 offered 1318 JAVA not offered

Page No: 77

27.

Create the following tables : Student (roll-no, name, subject-opted) Subject rank (subject-code, subject-name, faculty-code) Faculty (faculty-code, faculty-name, specialization) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) Find the number of students who have enrolled for the subject "DBMS" (ii) Find all those subjects which are not offered by any faculty members.

Sql> create table student(roll_no number(5) primary key,name varchar2(20),subject_opted varchar2(10)); Sql> create table faculty(faculty_code number(4)primary key,faculty_name varchar2(20), specialization varchar2(20)); Sql> create table subject_rank(subject_code number(4) primary key, subject_name varchar2(20), faculty_code number(4) references faculty(faculty_code));

Page No: 78

Sql> insert into subject_rank values(&subject_code,'&subject_name',&faculty_code); SQL> insert into faculty values(&faculty_code,'&faculty_name','&specialization'); Sql> insert into student values(&roll_no,'&name','&subject_opted',&subject_code);

SQL> select* from student; ROLL_NO NAME SUBJECT_OPTED SUBJECT_CODE ---------- -------------------- -------------------- -----------101 Anil DBMS 1313 102 RAJU SE 1315 103 DURGA OR 1314 104 BRAMAR OS 1316 105 SRIKANTH DAA 1317 SQL> select* from subject_rank; SUBJECT_CODE SUBJECT_NAME ------------ -------------------- -----------1313 DBMS 1000 1314 OR 1001 1315 SE 1002 1316 OS 1003 1317 DAA 1004 FACULTY_CODE

Page No: 79

SQL> select* from faculty; FACULTY_CODE FACULTY_NAME SPECIALIZATION ------------ -------------------- ------------------------------------------------------------1000 Ramesh M.TECH 1003 SIVA MCA 1002 RAJU M.Sc. 1004 RAJESH M.TECH 1001 KRISHNA M.Sc.

Sql>select count(name) from student s,subject_rank sr where s.subject_code=sr.subject_code and sr.subject_name='DBMS'; COUNT(NAME) ----------1

SQL> select subject_name from subject_rank where faculty_code is NULL; no rows selected

Page No: 80

28.

Create the following tables : Student (roll-no, name, subject-opted) Subject rank (subject-code, subject-name, faculty-code) Faculty (faculty-code, faculty-name, specialization) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) Find the number of students who have enrolled for the subject "DBMS" (ii) Find all those subjects which are offered by more than one faculty member.

Sql> create table student(roll_no number(5) primary key,name varchar2(20),subject_opted varchar2(10)); Sql> create table faculty(faculty_code number(4)primary key,faculty_name varchar2(20), specialization varchar2(20)); Sql> create table subject_rank(subject_code number(4) primary key, subject_name varchar2(20), faculty_code number(4) references faculty(faculty_code));

Page No: 81

Sql> insert into subject_rank values(&subject_code,'&subject_name',&faculty_code); SQL> insert into faculty values(&faculty_code,'&faculty_name','&specialization'); Sql> insert into student values(&roll_no,'&name','&subject_opted',&subject_code);

SQL> select* from student; ROLL_NO NAME SUBJECT_OPTED SUBJECT_CODE ---------- -------------------- -------------------- -----------101 Anil DBMS 1313 102 RAJU SE 1315 103 DURGA OR 1314 104 BRAMAR OS 1316 105 SRIKANTH DAA 1317 SQL> select* from subject_rank; SUBJECT_CODE SUBJECT_NAME ------------ -------------------- -----------1313 DBMS 1000 1314 OR 1001 1315 SE 1002 1316 OS 1003 1317 DAA 1004 FACULTY_CODE

Page No: 82

SQL> select* from faculty; FACULTY_CODE FACULTY_NAME SPECIALIZATION ------------ -------------------- ------------------------------------------------------------1000 Ramesh M.TECH 1003 SIVA MCA 1002 RAJU M.Sc. 1004 RAJESH M.TECH 1001 KRISHNA M.Sc.

Sql>select count(name) from student s,subject_rank sr where s.subject_code=sr.subject_code and sr.subject_name='DBMS'; COUNT(NAME) ----------1 SQL> select subject_name from subject_rank group by subject_name having count(*)>1; no rows selected

Page No: 83

29.

Create the following tables : Student (roll-no, name, subject-opted) Subject rank (subject-code, subject-name, faculty-code) Faculty (faculty-code, faculty-name, specialization) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) Find the number of students who have enrolled for the subject "OS" (ii) Find all those students who opted for more than 5 subjects.

Sql> select count(name) from student s,subject_rank sr where s.subject_code=sr.subject_code and sr.subject_name='OS'; COUNT(NAME) ----------1

SQL> select name from student group by name having count(*)>5; no rows selected

Page No: 84

30.

Create the following tables : Student (roll-no, name, subject-opted) Subject rank (subject-code, subject-name, faculty-code) Faculty (faculty-code, faculty-name, specialization) (a) Create a form to accept the data from the user with appropriate validation checks. (b) Generate queries to do the following : (i) Find the number of students who have not enrolled for the subject "DBMS" (ii) Find all those subjects which are offered by more than one faculty member.

Sql> select count(roll_no) from student s,subject_rank sr where sr.subject_code=s.subject_code and sr.subject_name not like 'DBMS'; SQL> select subject_name from subject_rank group by subject_name having count(*)>1; no rows selected

Page No: 85

Procedure for Report Builder to the given table:


BOOK(accession_no,title,publisher,author,status)

Page No: 86

Page No: 87

Page No: 88

Page No: 89

Page No: 90

Das könnte Ihnen auch gefallen