Lab Manual of Dbms
Lab Manual of Dbms
1. Course Objectives
2. Syllabus
3. Course Outcomes
1
4. Session Plan
S.No Week No Unit As Per
Syllabus Activity
1 1 Unit I 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.
2 1 Unit I 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) insert atleast 8 records into the
respective tables.
(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
List of Textbooks
Websites
https://www.javapoint.com/dbms-tutorial
https://www.tutorialspoint.com/dbms/index.htm
https://www.geeksforgeeks.org/dbms
http://www.guru99.com/dbms-tutorial.html
https://www.studytonight.com/dbms
5. Equipment required
Hardware
No. of System : 60(IBM)
Processor : PIV™ 1.67 GHz
RAM : 512 MB
Hard Disk : 40 GB
Optical
Mouse : Mouse
Network Interface card : Present
Software
Operating System : Window XP
Oracle
database
Software : 10G
6.
7. Code of Conduct
Students should report to the concerned lab as per the time table.
Students should be present in the labs for total scheduled duration.
Students who turn up late to the labs will in no case be permitted to do
the program scheduled for the day.
After completion of the program, certification of the concerned staff in-
charge in the observation book is necessary.
Student should bring a notebook of 100 pages and should enter the
readings/observations into the notebook while performing the
experiment.
The record of observations along with the detailed experimental
procedure of the experiment in the immediate last session should be
submitted and certified by the staff member in-charge.
Not more than 2-students in a group are permitted to perform the
experiment on the set.
Any damage caused to the systems / equipment will be viewed seriously
PROGRAM
SQL> create table sb_account (account_no number (5) primary key, customer_name
varchar2(20), balance_amount number(6));
Table created.
1 row inserted
1 row inserted
1 row inserted
1 row inserted
1 row inserted
ano sb_account.account_no%type;
balance sb_account.balance_amount%type;
withdraw number(5);
begin
withdraw:=&withdraw; 7 ano:=&account_no;
select balance_amount into balance from sb_account where 9 account_no=ano;
dbms_output.put_line('balance='||balance);
if(balance<1000) then
dbms_output.put_line('withdraw fails');
end if;
if(withdraw>balance) then
dbms_output.put_line('withdraw fails');
else
account_no=ano;
end if;
end;
/
Enter value for withdraw: 100 Enter value for
deposit number(5);
ano sb_account.account_no%type;
begin
Deposit:=&deposit;
ano:=&account_no;
end;
/
104
PROGRAM
Table Created
(i) List all those faculty members whose experience is greater than or equal to 10 years and
have M.Tech degree.
Fname
B
(ii) List all those faculty members, who have at least 10 years of experience but do not
have M.Tech degree.
Fname
A
B
E
Ex.No.3 CREATION OF LIBRARY INFORMATION SYSTEM TABLE
PROGRAM
SQL>create table book(accno number(3),title varchar2(10),publisher varchar2(15),
author varchar2(10),status varchar2(30),dateofpurchase date);
Table Created
1 row inserted
1 row inserted
1 row inserted
1 row inserted
1 row inserted
SQL> ed trg.sql;
begin
if (sysdate-dateofpurchase)/365>=20 then
:new.status:='cannot be issued';
end if;
end;
Trigger Created
SQL>select * from
book;
Status could be issued, present in the library, sent for binding, and account be issued
(a)insert minimum 8 records into the respective tables
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.
PROGRAM
SQL>create table book(accno number(3),title
varchar2(30),dateofpurchase date);
Table Created
1 row inserted
1 row inserted
1 row inserted
1 row inserted
1 row inserted
(ii) List all those books that cannot be issued and purchased 20 years ago.
PROGRAM
SQL>create table student(roll_no number(2),name
varchar2(20),dob date,course_id number(3));
Table Created
1 row inserted
1 row inserted
1 row inserted
1 row inserted
1 row inserted
Table Created
1 row inserted
1 row inserted
1 row inserted
(i) List all those students who are greater than 18 years of
(ii) List all those courses whose fee is greater than that of MCA course.
cname Fee
M.Tech 35000
MBA 33000
15
Ex.No.6 CREATION OF TABLES AND WITH NESTED QUERIES
PROGRAM
Table Created
1 A 10 5
2 B 50 60
3 C 150 100
4 D 100 100
5 icode iname stock reorder
6 F 95 50
7 G 70 70
8 H 65 0
9 I 100 90
10 J 110 100
Table Created
11
scode 1
icode
11 2
11 3
11 4
11 5
11 6
12 7
13 6
13 8
14 9
15 10
15 4
(i) List all those suppliers who can supply the given item.
SQL> select sname from supplier where scode=(select scode from cansupply where icode=(select
icode from item where iname=a));
Sname
AA
SQL> select iname from item where icode!=(select icode from cansupply where scode=(select
scode from supplier where sname=cc));
Iname
F
H
Ex.No.7 CREATION OF STUDENT TABLE WITH SUB QUERIES
PROGRAM
SQL>create table student(roll_no number(2),name varchar2(20),subject-name
varchar2(20));
Table Created
1 row inserted
1 row inserted
1 row inserted
1 row inserted
1 row inserted
Table Created
1 row inserted
1 row inserted
1 row inserted
1 row inserted
1 row inserted
(i) Find the number of students who have enrolled for the subject "DBMS".
No of students
2
(ii) Find all those faculty members who have not offered any subject.
SQL > CREATE TABLE student(roll char(10) PRIMARY KEY , dob date, name varchar2(10), courseid char(10));
table created.
SQL > CREATE TABLE course( courseid char(10) PRIMARY KEY , name varchar2(10),fee
number,2 duration number status varchar2(10));
table created.
insert into course values ('c001','mca',75000,3,'');
insert into course values ('m003','mba',200000,2,'');
insert into student values ('04808015', '07-sep-1990','suchitra','c001');
insert into student values ('04708015', '07-sep-1990','radhika','c001');
insert into student values ('04708012','12-jan-1988','hemasri','c001');
insert into student values ('04807010','26-dec-1990','jayasri','c001');
insert into student values ('04708016','07-jul-1985','radha','c001');
insert into student values ('04708013','12-jun-1988','hemalatha','c001');
insert into student values ('04807011','26-dec-1990','vasuda','c001');
insert into student values ('04808018','06-nov-1978','sadhana','c001');
insert into student values ('04708019','07-oct-1985','ragini','c001');
insert into student values ('04708020','21-feb-1988','anmol','m003');
insert into student values ('04807021','20-dec-1990','teja','m003');
insert into student values('0460909','17-jul-1990','kareena','c001');
(b) PL/SQL procedure to set the status of course to ‘not offered’ in which the number of candidates is
lessthan .
end;
PROGRAM
Table Created
1 A 10 5
2 B 50 60
3 C 150 100
4 D 100 100
5 icode iname Stock reorder
6 F 95 50
7 G 70 70
8 H 65 0
9 I 100 90
10 J 110 100
Table Created
11
scode 1
icode
11 2
11 3
11 4
11 5
11 6
12 7
13 6
13 8
14 9
15 10
15 4
CREATION:
SQL> @PR22
Procedure created.
EXECUTION:
SQL> EXECUTE PR22
SUCCESSFULLY UPDATED
OUTPUT:
SQL> SELECT * FROM supplier;
SQL > CREATE TABLE student(roll char(10) PRIMARY KEY ,dob date, name varchar2(10),courseid char(10));
table created.
SQL > CREATE TABLE course(courseid char(10) PRIMARY KEY , name varchar2(10),2 fee number, duration number);
table created.
insert into course values ('c001','mca',75000,3);
insert into course values ('m003','mba',200000,2);
PL/SQL procedure to set the status of course to 'offered' in which the number of candidates is at least 10 otherwise
set to ‘not offered’ .
PROGRAM
SQL> create table course(course-id number(4) primary key, name varchar2(10),fee
number(7),duration number(1));
Table created
1 row created
1 row created
1 row created
1 row created
1 row created
SQL>select*from course;
Table created
SQL> insert into student values(1,TbangT,T14-FEB-03T,101) ;
1 row created
1 row created
1 row created
1 row created
1 row created
SQL>select*from student;
Roll_no name dob Course_id
1 Bang 14-FEB-03 101
2 Maruthi 15-JAN-91 102
3 Kiran 14-NOV-89 104
4 Narasimha 03-OCT-94 103
5 Vignu 16-JAN-95 103
(i) List all those students who are between 18-19 years of age and have opted
5.
PROGRAM
Table Created
Table created
SQL> insert into customer values(201,’A’,’Hyderabad’,101);
1 row created
1 row created
1 row created
1 row created
(i) List all those customers who live in the same city as the branch in which
(ii) List all those customers who have an account in more than one branch.
Sql>
Cname
A
A
PROGRAM
SQL>create table book1(accession_no number(4) primary key, title
varchar2(15),publisher varchar2(15),year number(4),dopdate, status varchar2(20));
Table Created
1 row created
1 row created
1 row created
1 row created
1 row created
Table Created
1 row created
1 row created
1 row created
1 row created
1 row created
Table Created
1 row created
1 row created
1 row created
1 row created
(ii) Write a trigger to set the status of a book neither to "lost" which is
a) Procedure:
p11 is
ac_no book2.accession_no%type;
sta book2.status%type;
begin
ac_no:='&ac_no';
dbms_output.put_line('book issued');
else
end;
sql>@one.sql;
ac_no:105 procedure
created.
Sql>exec p11;
Book issued
Trigger:
sql> ed two.sql;
begin
if(:new.rack_position=00)then
end;
sql>@two.s
ql; trigger
created.
PROGRAM
Table Created
1 row created
1 row created
1 row created
1 row created
1 row created
Table Created
SQL>insert into member values(1,'sandeep',2,2);
1 row created
1 row created
1 row created
1 row created
1 row created
Table Created
1 row created
1 row created
1 row created
1 row created
SQL>insert into book_issue2 values(103,4,'15-feb-10');
1 row created
Procedure:
p11 is
ac_no book2.accession_no%type;
sta book2.status%type;
begin
ac_no:='&ac_no';
dbms_output.put_line('book issued');
else
end;
sql>@one.sql;
ac_no:105 procedure
created.
Sql> exec p11;
Book Issued
listed" if they have taken book but not returned even after
one year.
Trigger:
sql>edit tri2.sql;
before insert or
update on
book_issue2 for
each row
begin
if(:new.date_of_is
sue<'01-jan-
07')then update
book2 set
status='back
end;
sql> @tri2.sql;
trigger created.
x number(5);
y number(5);
z number(7);
begin
x:=10;
y:=20;
z:=x+y;
dbms_output.put_line('Sum is '||z);
end;
/
Output
Sum is 30
DECLARE
n1 NUMBER := &num1;
BEGIN
-- test if the number provided by the user is even
IF MOD(n1,2) = 0 THEN
DBMS_OUTPUT.PUT_LINE ('The number. '||n1||
' is even number');
ELSE
DBMS_OUTPUT.PUT_LINE ('The number '||n1||' is odd number.');
END IF;
DBMS_OUTPUT.PUT_LINE ('Done Successfully');
END;
/
Output
TABLE: client_master
TABLE : Product_master :
create table product_master (
product_no varchar2(6) primary
key, description varchar2(20),
profit_percent number(5,2),
unit_measure varchar2(8),
qty_on_hand number(6),
reoder_lvl number(6),
sell_price number(10),
cost_price number(10));
insert into product_master values ('P00001', '1.44floppies', 5, 'piece', 100, 20, 525,
500);
insert into product_master values('P03453', 'Monitors',6, 'piece', 10, 3, 12000, 11200);
insert into product_master values('P06734', 'Mouse',5, 'piece', 20, 5, 1050,
500);
insert into product_master values('P07865', '1.22 floppies', 5, 'piece', 100, 20, 525,
500);
insert into product_master values('P07868', 'Keyboards',2, 'piece', 10, 3, 3150, 3050);
insert into product_master values('P07885', 'CD Drive',2.5, 'piece',10, 3, 5250, 5100);
insert into product_master values('P07965', '540 HDD',4, 'piece', 10, 3, 8400, 8000);
insert into product_master values('P07975', '1.44 Drive',5, 'piece', 10, 3, 1050, 1000);
insert into product_master values('P08865', '1.22 Drive',5, 'piece', 2, 3, 1050, 1000);
iv) On the basis of above two tables answer the following Questionries:
Output:
ii) Retrieve the list of names and cities of all the clients.
iii) List the various products available from the product_master table.
Output:
iv) List all the clients who are located in Bombay.
Output:
Output:
vi) Find the products with description as ‘1.44 drive’ and ‘1.22 Drive’. select *
from
Output:
Ex.No.17 CREATION OF TABLES USING PRIMARY KEY
a)Find the products with description as '1.44 drive' and '1.22 Drive'.
b)Find all the products whose sell price is greater then 5000.
c)Find the list of all clients who stay in in city `Bombay' or city 'Delhi' or
`Madras'.
d)Find the product whose selling price is greater than 2000
and less than or equal to 5000.
e)List the name, city and state of clients not in the state of 'Maharashtra'
a) Find the products with description as ‘1.44 drive’ and ‘1.22 Drive’.
Output:
b) Find all the products whose sell price is greater then 5000.
c) Find the list of all clients who stay in in city ‘Bombay’ or city ‘Delhi’ or ‘Madras’.
Output:
d) Find the product whose selling price is greater than 2000 and less than or equal to 5000.
Output:
e) List the name, city and state of clients not in the state of ‘Maharashtra’.
Output:
iv) On the basis of above two tables answer the following Questionries:
b)Delete the record with client 0001 from the client master table.
Result:
output
e) Find the products whose selling price is more than 1500 and also find the new
selling price as original selling price *15.
select description from product_master where sell_price
> 1500; update product_master set
sell_price=sell_price*15;
select sell_price from product_master;
Output
e) Find out the clients who stay in a city whose second letter is a.
select * from CLIENT_MASTER where city like '_a%';
Output
f) Find out the name of all clients having ‘a’ as the second letter in their names.
Output
Output
insert into product_master values ('P00001', '1.44floppies', 5, 'piece', 100, 20, 525,
500);
insert into product_master values('P03453', 'Monitors',6, 'piece', 10, 3, 12000, 11200);
insert into product_master values('P06734', 'Mouse',5, 'piece', 20, 5, 1050,
500);
nsert into product_master values('P07865', '1.22 floppies', 5, 'piece', 100, 20, 525,
500);
insert into product_master values('P07868', 'Keyboards',2, 'piece', 10, 3, 3150, 3050);
insert into product_master values('P07885', 'CD Drive',2.5, 'piece',10, 3, 5250, 5100);
insert into product_master values('P07965', '540 HDD',4, 'piece', 10, 3, 8400, 8000);
insert into product_master values('P07975', '1.44 Drive',5, 'piece', 10, 3, 1050, 1000);
insert into product_master values('P08865', '1.22 Drive',5, 'piece', 2, 3, 1050, 1000);
Output:
Output:
Output:
d) Determine the maximum and minimum prices . Rename the tittle as ‘max_price’ and min_price
respectively.
Output:
e) Count the number of products having price greater than or equal to 1500.
Output:
create table product_master (product_no varchar2(6) primary key, description varchar2(20), profit_percent
number(5,2), unit_measure varchar2(8), qty_on_hand number(6), reoder_lvl number(6),sell_price number(10),
cost_price number(10));
insert into product_master values ('P00001', '1.44floppies', 5, 'piece', 100, 20, 525,
500);
insert into product_master values('P03453', 'Monitors',6, 'piece', 10, 3, 12000, 11200);
insert into product_master values('P06734', 'Mouse',5, 'piece', 20, 5, 1050,
500);
nsert into product_master values('P07865', '1.22 floppies', 5, 'piece', 100, 20, 525,
500);
insert into product_master values('P07868', 'Keyboards',2, 'piece', 10, 3, 3150, 3050);
insert into product_master values('P07885', 'CD Drive',2.5, 'piece',10, 3, 5250, 5100);
insert into product_master values('P07965', '540 HDD',4, 'piece', 10, 3, 8400, 8000);
insert into product_master values('P07975', '1.44 Drive',5, 'piece', 10, 3, 1050, 1000);
insert into product_master values('P08865', '1.22 Drive',5, 'piece', 2, 3, 1050, 1000);
iv) On the basis of above two tables answer the following Questionries:
1) find out the product which has been sold to 'ivan bayroos'.
Output:
2) find out the product and their quantities that will have to delivered in the current month.
select d.product_no,p.description,sum(d.qty_ordered)
from sales_order_details d,sales_order s,product_master p
where p.product_no=d.product_no and s.s_order_no=d.s_order_no and to_char(dely_date,'mon-
yy')=to_char(sysdate,'mon-yy')
group by d.product_no,p.description;
Output:
3) find the product_no and description of moving products.
Output:
4. Find out the names of clients who have purchased 'CD DRIVE'
Output:
5) List the product_no and s_order_no of customers having qty_ordered less than 5 from the order detail Table
for the product '1.44 Floppies'.
select d.product_no,d.s_order_no from sales_order_details d,sales_order s,product_master p
where s.s_order_no=d.s_order_no and p.product_no=d.product_no and d.qty_ordered<5 and
p.description='1.44 Floppies';
Output:
iv) On the basis of above two tables answer the following Questionries:
1. Find the products and their quantities for the orders placed by Wandan Saitwal ' and "Ivan
Bayross".
2. Find the products and their quantities for the orders placed by client_no " C00001" and
"C00002".
3. Find the order No„ Client No and salesman No. where client has been received by more than one
salesman.
4. Display the s_order_date in the format "dd-mm-yy" e.g. "12- feb-96"
5. Find the date , 15 days after date.
nsert into product_master values('P07865', '1.22 floppies', 5, 'piece', 100, 20, 525,
500);
insert into product_master values('P07868', 'Keyboards',2, 'piece', 10, 3, 3150, 3050);
insert into product_master values('P07885', 'CD Drive',2.5, 'piece',10, 3, 5250, 5100);
insert into product_master values('P07965', '540 HDD',4, 'piece', 10, 3, 8400, 8000);
insert into product_master values('P07975', '1.44 Drive',5, 'piece', 10, 3, 1050, 1000);
insert into product_master values('P08865', '1.22 Drive',5, 'piece', 2, 3, 1050, 1000);
1. Find the products and their quantities for the orders placed by 'Vandana Saitwal' and 'Ivan Bayross'.
Output:
2. Find the products and their quantities for the orders placed by client_no'C00001' and 'C00002'.
Output:
3. Find the order No,, Client No and salesman No. where a client has
been received by more than one salesman.
Output
Output:
Output:
1)Print the description and total quantity sold for each product.
2)Find the value of each product sold.
3)Calculate the average quantity sold for each client that has a maximum order
value of 15000.
4) Find out the products which has been sold to Ivan.
5) Find the names of clients who have 'CD Drive'.
iv) On the basis of above two tables answer the following Questionries:
1) Print the description and total quantity sold for each product.
Output:
2) Find the value of each product sold.
Output:
3) Calculate the average quantity sold for each client that has a maximum order
value of 15000.
Output:
Output:
SELECT CLIENT_MASTER.NAME
FROM SALES_ORDER_DETAILS
INNER JOIN SALES_ORDER ON SALES_ORDER_DETAILS.S_ORDER_NO = SALES_ORDER.S_ORDER_NO
INNER JOIN CLIENT_MASTER ON SALES_ORDER.CLIENT_NO= CLIENT_MASTER.CLIENT_NO
INNER JOIN PRODUCT_MASTER MASTER2 on SALES_ORDER_DETAILS.PRODUCT_NO =
MASTER2.PRODUCT_NO WHERE
MASTER2.DESCRIPTION LIKE 'CD_drive';
Output:
Ex.No.23 USING OPERATORS, JOINS AND CLAUSES
iv) On the basis of above two tables answer the following Questionnaires:
1) Find the products and their quantities for the orders placed by `Vandana' and
`Ivan'.
2)Select product_no, total qty ordered for each product.
3) Select product_no, product description and qty ordered for each product.
4)Display the order number and day on which clients placed their order.
5) Display the month and Date when the order must be delivered.
insert into product_master values ('P00001', '1.44floppies', 5, 'piece', 100, 20, 525,
500);
insert into product_master values('P03453', 'Monitors',6, 'piece', 10, 3, 12000, 11200);
insert into product_master values('P06734', 'Mouse',5, 'piece', 20, 5, 1050,
500);
nsert into product_master values('P07865', '1.22 floppies', 5, 'piece', 100, 20, 525,
500);
insert into product_master values('P07868', 'Keyboards',2, 'piece', 10, 3, 3150, 3050);
insert into product_master values('P07885', 'CD Drive',2.5, 'piece',10, 3, 5250, 5100);
insert into product_master values('P07965', '540 HDD',4, 'piece', 10, 3, 8400, 8000);
insert into product_master values('P07975', '1.44 Drive',5, 'piece', 10, 3, 1050, 1000);
insert into product_master values('P08865', '1.22 Drive',5, 'piece', 2, 3, 1050, 1000);
iV) On the basis of above two tables answer the following Questionnaires:
1) Find the products and their quantities for the orders placed by `Vandana' and
`Ivan'.
Output:
3) Select product_no, product description and qty ordered for each product.
Output:
4) Display the order number and day on which clients placed their order.
SELECT
TO_CHAR(SALES_ORDER.S_ORDER_DATE,'DAY'),SALES_ORDER.S_ORDER_NO FROM
SALES_ORDER;
Output:
5) Display the month and Date when the order must be delivered.
SELECT
TO_CHAR(SALES_ORDER.S_ORDER_DATE,'MONTH'),SALES_ORDER.DELY_DATE
FROM SALES_ORDER;
Output:
Ex.No.24 CREATION OF STUDENT AND STUDENT-RANK TABLE
PL/SQL procedure to set the status of the subject to’not offered’ if the subject is not opted by at least5
students.
6 rows SELECTED.
Ex.No.25 CREATION OF STUDENT AND COURSE TABLE USING PRIMARY KEY
SQL>CREATE TABLE student( roll char(10) PRIMARY KEY , dob date, name
varchar2(10),courseid char(10));
table created;
CREATE TABLE course(courseid char(10) PRIMARY KEY , name varchar2(10), fee number,
durationnumber);
table created;
SQL >INSERT into course values ('c001','mca',75000,3);
1 row created.
SQL >INSERT into course values ('m003','mba',200000,2);
1 row created.
SQL >INSERT into student values ('04808015','06-aug-1978','suchitra','c001');
1 row created.
SQL >INSERT into student values ('04708015','07-sep-1991','radhika','c001');
1 row created;
PROCEDURE:
SQL> declare2
c_id course18.course_id%type;
ctr number;
cursor c20 is select course_id from course20;
begin
open c20;
loop
fetch c20 into c_id;
select count(roll_no) into ctr from student20 where course_id=c_id;
if(ctr>=10) then
update course20 set status='offered' where course_id=c_id;
else
update course20 set status=' not offered' where course_id=c_id;
end if;
exit when c20 % notfound;
dbms_output.put_line('table has been updated');
end loop;
close c20;
end;
OUTPUT:
table has been updated
table has been updated
table has been updated
PL/SQL procedure successfully completed.
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 book(accno number PRIMARY KEY ,title varchar2(50),publisher
varchar(25),authorvarchar2(25),dop date);
table created.
SQL > ALTER TABLE book add (status varchar2(50));table altered.
SQL > ALTER TABLE book add constraint c1 check (status in ('issued','present in library','sent for binding','a/cbe
issued'))table altered.
SQL > desc bookname null?
typeaccno not null numbertitle varchar2(50)publisher varchar2(25)author varchar2(25)dop datestatus
varchar2(50));
SQL >INSERT
intobook(accno,publisher,status,title,author,dop)values(&acno,'&pub','&st','&title','&author','&dop');
enter value for acno: 100
enter value for pub: tataenter value for st: issued
enter value for title: networka
enter value for author: stallings
enter value for dop: 01-aug-84old
1:INSERT intobook(accno,publisher,status,title,author,dop)values(&acno,'&pub','&st','&title','&author','&dop'
)
new
1:INSERT intobook(accno,publisher,status,title,author,dop)values(100,'tata','issued','networka','stallings','01-
aug-84')1 row created.
SQL > /enter value for acno: 180
enter value for pub: oracle
enter value for st: abcd
enter value for title: ad
List all those books which are new arrivals. the books which are acquired during the last 6 months are
categorized as new arrivals.
commit complete.
declare
i number(2);
n number(2);
begin
n:=&n;
for i in 1..10 loop
dbms_output.put_line( n || ' * ' || i || ' = ' || n*i);
end loop;
end;
output
Enter value for n: 5
old 6: n:=&n;
new 6: n:=5;
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
begin
n:=5432112345;
m:=n;
if m = temp
then
dbms_output.put_line('true');
else
dbms_output.put_line('false');
end if;
end;
/
Output:
True
Ex.No.28 CREATION OF TABLES USING PRIMARY KEY AND SUBQUERIES
SQL > CREATE TABLE student( roll char(10) PRIMARY KEY , dob date, name varchar2(10),courseid char(10));
table created.
SQL > CREATE TABLE course(courseid char(10) PRIMARY KEY , name varchar2(10), fee number, durationnumber);
table created.
SQL >INSERT into course values ('c001','mca',75000,3);
1 row created.
SQL >INSERT into course values ('m003','mba',200000,2);
1 row created.
SQL >INSERT into student values ('04808015','06-aug-1978','suchitra','c001');
1 row created.
SQL >INSERT into student values ('04708015','07-sep-1991','radhika','c001');
1 row created.
(b) (i) list all student names who have opted for mca course and are above 18 yrs of age.
SQL >SELECT s.name "student list" from student "s",course "c" where
(months_between(sysdate,dob)/12)>=18 and c.name='mca' and c.courseid=s.courseid;
student li
----------
suchitra
(b)(ii) List all the course whose fee is more than course’mca’.
SQL > SELECT c.name from course "c"2 where fee > (SELECT fee from course where name='mca');
Name
----------
mba
SQL> CREATE table BOOK1(AC_NO number PRIMARY KEY,TITLE varchar2(8),PUBLISHER varchar2(8),YEAR number,D_O_PUR
date,STATUS varchar2(17));
Table created.
SQL> CREATE table MEMBER(M_ID number PRIMARY KEY,NAME varchar2(10),NO_OF_BOOK number,M_LIMIT number,STATUS
varchar2(10));
Table created.
SQL> CREATE table BOOK_ISSUE(AC_NO number REFERENCES BOOK1(ac_no),M_ID number REFERENCES MEMBER(m_id),D_O_ISSUE
date);
Table created.
VALUE INSERTION:
1 row created.
SQL> INSERT into member VALUES('&m_id','&name','&no_of_book_issued','&max_limit');
Enter value for m_id: 1
Enter value for name: LAXMI
Enter value for no_of_book_issued: 1
Enter value for max_limit: 4
old 1: INSERT into member VALUES('&m_id','&name','&no_of_book_issued','&maxlimit')
new 1: INSERT into member VALUES('1','LAXMI','1','4')
1 row created.
SQL> INSERT into book_issue VALUES('&ac_no','&m_id','&d_o_issue');
Enter value for ac_no: 111
Enter value for m_id: 5
Enter value for d_o_issue: 14-oct-2009
old 1: INSERT into book_issue VALUES('&ac_no','&m_id','&d_o_issue')
new 1: INSERT into book_issue VALUES('111','5','14-oct-2009')
1 row created.
TABLE VALUES:
TRIGGER:
DECLARE
CURSOR c1 is SELECT d_o_issue,m_id from book_issue;
Begin
for i in c1
loop
if ADD_MONTHS(i.d_o_issue,12)<=sysdate then
UPDATE member set status='back listed' where m_id=i.m_id;
end if;
end loop;
End;
/
PL/SQL PROCEDURE with name pro1:
BEGIN
SELECT no_of_book,m_limit into n,m from member WHERE m_id=mid;
if m>n then
INSERT into book_issue VALUES(acno,mid,doi);
dbms_output.put_line('VALUE SUCCESSFULLY INSERTED');
n:=n+1;
else
dbms_output.put_line('MAX LIMIT REACHED FOR THIS MEMBER');
end if;
UPDATE member set no_of_book=n WHERE m_id=mid;
END pro1;
/
CREATION:
SQL> @pro1
Enter value for accssion_no: 115
Enter value for member_id: 1
Enter value for date_of_issue: 23-sep-2008
old 5: Insert into book_issue values(&accssion_no,&member_id,'&date_of_issue')
new 5: Insert into book_issue values(115,1,'23-sep-2008');
Procedure created.
EXECUTION:
6 rows selected.
Ex.No.30 CREATION OF TABLES AND USING QUERIES
SQL > CREATE TABLE branch( branchid char(5) PRIMARY KEY ,name varchar2(10),city varchar2(10));
table created.
SQL > CREATE TABLE customer(custid char(5) PRIMARY KEY , name varchar2(20),city varchar2(10),branchid
char(5));
table created.
SQL >INSERT into branch values('b002','chikkad','hyd');
1 row created.
SQL >INSERT into branch values('b003','marred','sec');
1 row created.
SQL >INSERT into customer values('c002','suchitra2','hyd','b002');
1 row created.
SQL >INSERT into customer values('c003','suchitra3','hyd','b002');
1 row created.
SQL >INSERT into customer values('c004','suchitra4','hyd','b003');
1 row created.
List all those customers who live in the same city as the branch in which they have account.