0% found this document useful (0 votes)
126 views131 pages

NITIN Rdbms Assignment

The document provides the details of assignments to create tables, insert data, and write queries to retrieve data from the tables. 1. The first assignment involves creating tables to store deposit, branch, customer, and borrow details according to the given definitions. 2. The second assignment involves writing queries to list data from the created tables, retrieve specific fields, and apply filters based on conditions. 3. The third assignment involves writing more complex queries involving joins across multiple tables to retrieve matching or related records according to the given conditions.

Uploaded by

nitinsingaur.biz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views131 pages

NITIN Rdbms Assignment

The document provides the details of assignments to create tables, insert data, and write queries to retrieve data from the tables. 1. The first assignment involves creating tables to store deposit, branch, customer, and borrow details according to the given definitions. 2. The second assignment involves writing queries to list data from the created tables, retrieve specific fields, and apply filters based on conditions. 3. The third assignment involves writing more complex queries involving joins across multiple tables to retrieve matching or related records according to the given conditions.

Uploaded by

nitinsingaur.biz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 131

Assignment No.

1. Create the Tables according to the following Definition -

Table Deposit
ACTNO VARCHAR2(5)
CNAME VARCHAR2(20)
BNAME VARCHAR2(18)
AMOUNT NUMBER(8,2)
ADATE DATE
Query:- create table Deposit(ACNO VARCHAR2(5) primary key,CNAME
VARCHAR2(20),BNAME VARCHAR2(18),AMOUNT NUMBER(8,2),ADATE DATE) ;
Output:-

Table Branch
BNAME VARCHAR2(18)
CITY VARCHAR2(18)
Query:- create table Branch(BNAME VARCHAR2(18),CITY VARCHAR2(18));
Output:-

NITIN KUMAR SINGAUR 1|Page MCA – 1st SEMESTER


Table Customer
CNAME VARCHAR2(20)
CITY VARCHAR2(18)
Query:- create table Customer(CNAME VARCHAR(20) PRIMARY KEY,CITY
VARCHAR2(18));
Output:-

Table Borrow
LOANNO VARCHAR2(5)
CNAME VARCHAR2(20)
BNAME VARCHAR2(18)
AMOUNT NUMBER(8,2)
Query:- create table Borrow(LOANNO VARCHAR2(5),CNAME
VARCHAR2(20),BNAME VARCHAR2(18),AMOUNT NUMBER(8,2),PRIMARY
KEY(LOANNO),FOREIGN KEY(CNAME) REFERENCES CUSTOMER);
Output:-

NITIN KUMAR SINGAUR 2|Page MCA – 1st SEMESTER


2.Describe tables which are already created.
Query:- desc Deposit;
Output:-

Query:-desc Branch;
Output:-

Query:-desc Customer;
Output:-

NITIN KUMAR SINGAUR 3|Page MCA – 1st SEMESTER


Query:-desc Borrow;
Output:-

3. Insert the following Data

Table Deposit
Account Branch Name Amount Amount Date
NumberCusto
mer Name

100ANIL VRCE 1000 01/03/95

101SUNIL AJNI 5000 04/01/96

102MEHUL KAROLBAGH 3500 17/11/95

103MADHURI MG ROAD 1200 17/12/95

104PRAMOD ANDHERI 3000 31/03/96

105SANDIP VIRAR 2000 05/09/95

106SHIVANI NEHRU PALACE 1000 02/06/95

107KRANTI POWAI 5000 10/08/95

108SHALINI VRCE 7000 28/10/96

109SANJANA ANDHERI 4000 04/04/96

NITIN KUMAR SINGAUR 4|Page MCA – 1st SEMESTER


Output:-

Table Branch

Branch Name City

VRCE NAGPUR

AJNI NAGPUR

KAROLBAGH DELHI

MG ROAD BANGLORE

ANDHERI MUMBAI

VIRAR MUMBAI

NEHRU DELHI
PALACE

POWAI MUMBAI

GE ROAD BANGLORE

ANDHERI MUMBAI

NITIN KUMAR SINGAUR 5|Page MCA – 1st SEMESTER


Output:-

Table Customer

Customer Name City

ANIL KOLKATA

SUNIL DELHI

MEHUL BARODA

MADHURI PATNA

PRAMOD NAGPUR

SANDIP NAGPUR

SHIVANI SURAT

KRANTI MUMBAI

SHALINI MUMBAI

SANJANA MUMBAI

NITIN KUMAR SINGAUR 6|Page MCA – 1st SEMESTER


Output:-

Table Borrow

Loan Number Customer Name Branch Name Amount

201 ANIL VRCE 10000

206 MEHUL KAROLBAGH 50000

311 SUNIL AJNI 30000

321 MADHURI ANDHERI 20000

375 PRAMOD VIRAR 80000

481 SANJANA NEHRU PALACE 30000

Output:-

NITIN KUMAR SINGAUR 7|Page MCA – 1st SEMESTER


Assignment No. 2

1. List all data from table DEPOSIT


Query:- select * from Deposit;

Output:-

2. List all data from table BORROW


Query:- select * from Borrow;

Output:-

NITIN KUMAR SINGAUR 8|Page MCA – 1st SEMESTER


3. List all data from table CUSTOMER
Query:- select * from Customer;
Output:-

4. List all data from table BRANCH


Query:-SQL> select * from Branch;
Output:-

NITIN KUMAR SINGAUR 9|Page MCA – 1st SEMESTER


5.Give Account No. And amount of depositors:-
Query:- select ACNO,AMOUNT from Deposit;

Output:-

6.Give customer name and account no. Of depositers


Query:- select CNAME,ACNO FROM Deposit;
Output:-

NITIN KUMAR SINGAUR 10 | P a g e MCA – 1st SEMESTER


7.Give names of Customers
Query:- select CNAME from Deposit;
Output:-

8.Give names of branches


Query:-select BNAME from Branch;
Output:-

NITIN KUMAR SINGAUR 11 | P a g e MCA – 1st SEMESTER


9.Give names of borrower
Query:- select CNAME from Borrow;
Output:-

10.Give names of customers living in City Nagpur


Query:-select CNAME from Customer where CITY='NAGPUR';
Output:-

11.Give names of depositers having amount greater than 4000


Query:-select CNAME from Deposit where AMOUNT>4000;
Output:-

NITIN KUMAR SINGAUR 12 | P a g e MCA – 1st SEMESTER


12.Give account date of customer Anil
Query:- SELECT ADATE FROM Deposit WHERE CNAME='ANIL';
Output:-

13.Give names of all branches located in city Mumbai.


Query:-SQL> SELECT BNAME FROM Branch WHERE CITY='MUMBAI';
Output:-

14.Give names of borrower having loan no 205


Query:-SQL> select CNAME FROM Borrow where LOANNO=205;
Output:-
NITIN KUMAR SINGAUR 13 | P a g e MCA – 1st SEMESTER
15.Give names of depositors having account at VRCE
Query:-SQL> SELECT CNAME FROM DEPOSIT WHERE BNAME='VRCE';
Output:-

16.Give names of all branches located in City Delhi


Query:-SQL> SELECT BNAME FROM Branch WHERE CITY='DELHI';
Output:-

17.Give names of customers who opened account after date 01/12/96


Query:-SQL> SELECT CNAME FROM DEPOSIT WHERE ADATE>'01-DEC-96';
Output:-

NITIN KUMAR SINGAUR 14 | P a g e MCA – 1st SEMESTER


18.Give account number and deposit amount of customer having account opened
between dates 1-12-96 and 01-06-96
Query:-SQL> SELECT ACNO,AMOUNT FROM Deposit WHERE ADATE>='01-DEC-
95' AND ADATE<='01-MAY-96’;
Output:-

19.Give names of the city where branch Karolbagh is located


Query:-SQL> SELECT CITY FROM Branch WHERE BNAME=’KAROLBAGH’;
Output:-

20.Give details of Customer Anil


Query:- SQL> SELECT * FROM Deposit WHERE CNAME='ANIL';
Output:-

NITIN KUMAR SINGAUR 15 | P a g e MCA – 1st SEMESTER


NITIN KUMAR SINGAUR 16 | P a g e MCA – 1st SEMESTER
Assignment No. - 3
1. Give name of Customer having living city Mumbai and Branch city Nagpur.
Query:- SQL> SELECT C.CNAME FROM Deposit D,Customer C ,Branch B
WHERE C.CITY='MUMBAI' AND B.CITY='NAGPUR' AND D.CNAME=C.CNAME
AND B.BNAME=D.BNAME;
Output:-

2.Give names of Customer having the same living city as their Branch City.

Query:- SQL> SELECT Customer.CNAME FROM Customer,Branch JOIN DEPOSIT


ON DEPOSIT.BNAME=Branch.BNAME WHERE
CUSTOMER.CITY=BRANCH.CITY AND CUSTOMER.CNAME=DEPOSIT.CNAME;
Output:-

3.Give names of Customers who are borrowers as well as depositers and living city
Nagpur
Query:- select Customer.CNAME from Deposit,Borrow,Customer
where Deposit.CNAME= Borrow.CNAME and Customer.CNAME=Borrow.CNAME
and Customer.CNAME=Deposit.CNAME and Customer.CITY='NAGPUR'

Output :-

NITIN KUMAR SINGAUR 17 | P a g e MCA – 1st SEMESTER


4.Give names of depositers having the same living city as that of Mr. Anil and having the
deposit amount greater than 2000.
Query:-SQL> SELECT CNAME FROM Deposit, Branch WHERE
Branch.BNAME=Deposit.BNAME AND Branch.CITY=(SELECT Branch.CITY FROM
Branch , Deposit WHERE Deposit.BNAME=Branch.BNAME AND
Deposit.CNAME='ANIL') AND Deposit.AMOUNT>2000;
Output:-

5.Give names of Customers who are depositers and have the same branch city as that of
Mr. Sunil
Query:-SQL> select CNAME from Deposit JOIN Branch on
Deposit.BNAME=Branch.BNAME WHERE Branch.CITY =(SELECT Branch.CITY
FROM Branch JOIN DEPOSIT ON Deposit.BNAME=Branch.BNAME WHERE
Deposit.CNAME='SUNIL');

Output:-

NITIN KUMAR SINGAUR 18 | P a g e MCA – 1st SEMESTER


6.Give names of borrowers having deposit amount greater than 1000 and loan amount
greater than 20000
Query:-SQL> select Deposit.CNAME from Deposit , Borrow where
Borrow.CNAME=Deposit.CNAME AND Deposit.AMOUNT>1000 AND
Borrow.AMOUNT>20000;

Output:-

7.Give names of depositers having the same branch as the branch of Sunil
Query:-SQL> SELECT CNAME FROM DEPOSIT WHERE BNAME=(SELECT BNAME
FROM DEPOSIT WHERE CNAME='SUNIL');
Output:-

8.Give names of borrowers having loan amount greater than the loan amount of
Pramod
Query:-SQL> select B.BNAME from Borrow B,Deposit D where D.BNAME=B.BNAME and
B.AMOUNT>=(select amount from Borrow where CNAME='PRAMOD');
Output:-

9.Give names of customers living in the City where branch of Depositer Sunil is located
NITIN KUMAR SINGAUR 19 | P a g e MCA – 1st SEMESTER
Query:-SQL> select CNAME from Customer where CITY=(select Branch.CITY from
Branch,Deposit where Deposit.BNAME=Branch.BNAME AND Deposit.CNAME='SUNIL');
Output:-

10.Give loan number and loan amount of borrowers having the same branch as that of
Sunil
Query:-SQL> SELECT LOANNO,AMOUNT FROM BORROW WHERE
BNAME=(SELECT BNAME FROM DEPOSIT WHERE CNAME='SUNIL');
Output:-

11.Give loan number, Loan Amount, Account number and deposit amount of customer
having in city Nagpur
Query:-SQL> SELECT B.LOANNO,B.AMOUNT,D.ACNO,D.AMOUNT FROM
BORROW B,DEPOSIT D,CUSTOMER C WHERE D.CNAME=C.CNAME AND
C.CITY='NAGPUR' AND B.BNAME=D.BNAME;

Output:-

12.Give loan number, Loan Amount, Account number and deposit amount of customer
having branch located in Mumbai
NITIN KUMAR SINGAUR 20 | P a g e MCA – 1st SEMESTER
Query:-SQL> select b.LOANNO,b.AMOUNT,d.ACNO,d.AMOUNT from Deposit d,Borrow b,Customer
c,Branch br where C.CNAME=D.CNAME and D.BNAME=Br.BNAME and Br.CITY in(select CITY from
Branch where CITY='MUMBAI');
Output:-

13.Give oan number, Loan Amount, Account number, deposit amount, Branch Name,
Branch City and Living City of Pramod
Query:- select b.LOANNO,b.AMOUNT,d.ACNO,d.AMOUNT,br.BNAME,br.CITY,c.CITY
from Deposit d, Borrow b,Customer c,Branch br where b.CNAME=c.CNAME and d.CNAME =
c.CNAME and c.CITY=br.CITY and c.CNAME=’PRAMOD’;

Output:-

14.Give deposit details and loan details of customer in the city where Pramod is living
Query:-SQL> SELECT * FROM DEPOSIT,BORROW,CUSTOMER WHERE
CUSTOMER.CITY=(SELECT CITY FROM CUSTOMER WHERE CNAME='PRAMOD')
AND BORROW.CNAME=CUSTOMER.CNAME AND BORROW.CNAME
=DEPOSIT.CNAME ;

Output:-

NITIN KUMAR SINGAUR 21 | P a g e MCA – 1st SEMESTER


15.Give names of depositers having the same branch city as that of Mr. Sunil and having
the same living city as that of Mr. Anil
Query:-SQL> SELECT DEPOSIT.CNAME FROM CUSTOMER,DEPOSIT,BRANCH
WHERE BRANCH.BNAME=DEPOSIT.BNAME AND BRANCH.CITY=(SELECT CITY
FROM BRANCH WHERE BNAME=(SELECT BNAME FROM DEPOSIT WHERE
CNAME='SUNIL')) AND CUSTOMER.CITY=(SELECT CITY FROM CUSTOMER
WHERE CNAME='ANIL');
Output:-

16.Give names of depositers having amount greater than 5000 and having the same
living city as Mr. Pramod
Query:-SQL> SELECT DEPOSIT.CNAME FROM DEPOSIT ,CUSTOMER WHERE
CUSTOMER.CNAME=DEPOSIT.CNAME AND CUSTOMER.CITY=(SELECT CITY

FROM CUSTOMER WHERE CNAME='PRAMOD') AND AMOUNT>5000;


Output:-

NITIN KUMAR SINGAUR 22 | P a g e MCA – 1st SEMESTER


17.Give city of customer having the same branch city as that of Mr. Pramod

Query:-SQL> SELECT CUSTOMER.CITY FROM CUSTOMER,DEPOSIT,BRANCH


WHERE CUSTOMER.CNAME=DEPOSIT.CNAME AND BRANCH.CITY IN(SELECT
CITY FROM BRANCH WHERE BNAME=(SELECT BNAME FROM DEPOSIT WHERE
CNAME='PRAMOD')) AND DEPOSIT.BNAME=BRANCH.BNAME;
Output:-

18.Give branch city and living city of Pramod


Query:-SQL> SELECT BRANCH.CITY,CUSTOMER.CITY FROM
BRANCH,CUSTOMER ,DEPOSIT WHERE CUSTOMER.CNAME='PRAMOD'AND
CUSTOMER.CNAME=DEPOSIT.CNAME AND BRANCH.BNAME=DEPOSIT.BNAME;
Output:-

19.Give branch city of Sunil and branch city of Anil


Query:- SQL> SELECT B.CITY FROM BRANCH B,DEPOSIT D WHERE
D.BNAME=B.BNAME AND D.CNAME IN('SUNIL','ANIL');

Output:-

NITIN KUMAR SINGAUR 23 | P a g e MCA – 1st SEMESTER


20.Give the living city of Mehul and the living City of Sanjana
Query:-SQL>SELECT CITY FROM CUSTOMER WHERE CNAME='MEHUL' OR CNAME=
'SANJANA';
Output:-

NITIN KUMAR SINGAUR 24 | P a g e MCA – 1st SEMESTER


Assignment No. - 4

1. List all the customers who are depositers but not borrowers
Query:- SQL> select CNAME from Deposit minus(select CNAME from Borrow);

Output:-

2.List all the customers who are both depositers and borrowers.
Query:-SQL> SELECT CNAME FROM DEPOSIT INTERSECT SELECT CNAME FROM
BORROW;

Output:-

3.List all the customers, along with their amount who are either borrowers or depositers
NITIN KUMAR SINGAUR 25 | P a g e MCA – 1st SEMESTER
and living city Nagpur
Query:-SQL> SELECT DEPOSIT.CNAME FROM DEPOSIT,BORROW,CUSTOMER
WHERE CUSTOMER.CNAME=DEPOSIT.CNAME AND
BORROW.CNAME=DEPOSIT.CNAME AND CUSTOMER.CITY='NAGPUR';
Output:-

4.List all the depositers having deposit in all the branches where Sunil is having an
account.
Query:-SQL> SELECT DEPOSIT.CNAME FROM DEPOSIT,BRANCH WHERE
BRANCH.BNAME=DEPOSIT.BNAME AND DEPOSIT.BNAME IN(SELECT CNAME
FROM DEPOSIT WHERE CNAME='SUNIL');
Output:-

5.List all the customers living in City Nagpur and having branch city Mumbai or Delhi
Query:-SQL> select Customer.CNAME from Customer,Deposit,Branch where
Branch.BNAME=Deposit.BNAME and Customer.CNAME=Deposit.CNAME and
Customer.CITY='NAGPUR' and Branch.CITY in('MUMBAI','DELHI

Output:-

NITIN KUMAR SINGAUR 26 | P a g e MCA – 1st SEMESTER


6.List all the depositers living in city Nagpur
Query:-SQL> select Customer.CNAME from Customer,Deposit
where Deposit.CNAME=Customer.CNAME and
Customer.CITY='NAGPUR';

Output:-

7.List all the depositers living in city Nagpur and having branch in city Mumbai
Query:-SQL> select Deposit.CNAME from Deposit,Customer,Branch where
Deposit.CNAME=Customer.CNAME AND Deposit.BNAME=Branch.BNAME AND
Customer.CITY='NAGPUR' OR Branch.CITY='MUMBAI';
Output:-

8.List the branch city of Anil and Sunil


Query:- SQL> SELECT B.CITY FROM BRANCH B,DEPOSIT D WHERE
D.BNAME=B.BNAME AND D.CNAME IN('SUNIL','ANIL');

Output:-

NITIN KUMAR SINGAUR 27 | P a g e MCA – 1st SEMESTER


9.List the customers having deposit greater than 1000 and loan less than 10000.

Query:-SQL> select Deposit.CNAME from Deposit,Borrow where


Deposit.cname=Borrow.CNAME and Deposit.AMOUNT>1000 or Borrow.AMOUNT<10000;

Output:-

10.List the borrowers having branch city same as that of Mr. Sunil.
Query:-SQL> SELECT CNAME FROM BORROW WHERE BNAME=(SELECT BNAME
FROM BORROW WHERE CNAME='SUNIL');
Output:-

11.List the cities of depositers having branch VRCE


Query:-SQL> SELECT BRANCH.CITY FROM BRANCH,DEPOSIT WHERE
DEPOSIT.BNAME=BRANCH.BNAME OR BRANCH.CITY='VRCE';
Output:-

12.List the depositer having tha same living city as that of Mr. Sunil and the same
branch city as that of mr. Sunil.
NITIN KUMAR SINGAUR 28 | P a g e MCA – 1st SEMESTER
Query:-SQL> SELECT DEPOSIT.CNAME FROM DEPOSIT,CUSTOMER,BRANCH
WHERE CUSTOMER.CNAME=DEPOSIT.CNAME AND
BRANCH.BNAME=DEPOSIT.BNAME AND CUSTOMER.CITY=(SELECT CNAME
FROM DEPOSIT WHERE CNAME='SUNIL') AND BRANCH.CITY=(SELECT CNAME
FROM CUSTOMER WHERE CNAME='SUNIL');
Output:-

13.List the depositers having amount less than 1000 and living in the same city as Mr.
Anil
Query:-SQL> SELECT DEPOSIT.CNAME FROM DEPOSIT,CUSTOMER WHERE
DEPOSIT.CNAME=CUSTOMER.CNAME AND DEPOSIT.AMOUNT<=1000 AND
CUSTOMER.CITY=(SELECT CNAME FROM CUSTOMER WHERE CNAME='ANIL');
Output:-

14.List all the customers who are both Depositors and borrowers and living in the same
city as Mr. Anil
Query:-SQL> SELECT DEPOSIT.CNAME FROM DEPOSIT,BORROW,CUSTOMER
WHERE CUSTOMER.CNAME=DEPOSIT.CNAME AND
BORROW.CNAME=DEPOSIT.CNAME OR CUSTOMER.CITY=(SELECT CNAME
FROM CUSTOMER WHERE CNAME=’ANIL’);
Output:-

15.List all the cities where branches of Anil and SunIl are located
Query:-SQL> select Customer.CITY from Branch B,Customer,Deposit D where

NITIN KUMAR SINGAUR 29 | P a g e MCA – 1st SEMESTER


D.BNAME=B.BNAME and Customer.CNAME=D.CNAME and D.CNAME in ('SUNIL','ANIL');
Output:-

16.List all the customers name and amount for depositers living in the city where either
Anil or Sunil is Living
Query:-SQL> SELECT D.CNAME,D.AMOUNT FROM DEPOSIT D,CUSTOMER C
WHERE C.CNAME=D.CNAME AND C.CITY IN(SELECT C1.CITY FROM
CUSTOMER C1 WHERE C1.CNAME IN('SUNIL','ANIL'));
Output:-

17.List the amount for the depositers living in the city whete Anil is living
Query:-SQL> SELECT DEPOSIT.AMOUNT FROM DEPOSIT JOIN CUSTOMER ON
CUSTOMER.CNAME=DEPOSIT.CNAME WHERE CUSTOMER.CITY =(SELECT
CNAME FROM CUSTOMER WHERE CNAME='ANIL');
Output:-

NITIN KUMAR SINGAUR 30 | P a g e MCA – 1st SEMESTER


18.List the cities which are either branch city of Anil or living city of Sunil
Query:-SQL> SELECT CUSTOMER.CITY FROM DEPOSIT JOIN CUSTOMER
ON CUSTOMER.CNAME=DEPOSIT.CNAME WHERE CUSTOMER.CITY IN(SELECT
CNAME FROM CUSTOMER WHERE CNAME IN('ANIL','SUNIL'));
Output:-

19.List the customers who are borrowers or depositers and having living city Nagpur
and branch city as that of Mr. Sunil.
Query:-SQL> SELECT DEPOSIT.CNAME FROM
DEPOSIT,BORROW,CUSTOMER,BRANCH WHERE
CUSTOMER.CNAME=DEPOSIT.CNAME AND BORROW.CNAME=DEPOSIT.CNAME
AND DEPOSIT.BNAME=BRANCH.BNAME AND CUSTOMER.CITY='NAGPUR' AND
BRANCH.CITY=(SELECT CNAME FROM CUSTOMER WHERE CNAME='SUNIL');
Output:-

20.List the customers who are both borrowers and depositers and having the same
branch city as that of Mr. Anil.
Query:-SQL> select Deposit.CNAME from Deposit,Borrow,Customer,Branch where
Customer.CNAME=Deposit.CNAME AND Borrow.CNAME=Deposit.CNAME AND
Deposit.BNAME=Branch.BNAME AND Branch.CITY=(SELECT CNAME FROM
CUSTOMER WHERE CNAME='ANIL');

Output:-

NITIN KUMAR SINGAUR 31 | P a g e MCA – 1st SEMESTER


Assignment No. - 5

1.List total loan


Query:-SQL> select sum(AMOUNT) FROM Deposit;
Output:-

2. List total deposit


Query:-SQL> select sum(AMOUNT) FROM borrow;
Output:-

3.List total loan taken from Karolbagh branch.


Query:-SQL> select sum(AMOUNT) FROM Deposit where BNAME='KAROLBAGH';
Output:-

4.List total deposit of customer having account date later than 1 Jan 96. Query:-
NITIN KUMAR SINGAUR 32 | P a g e MCA – 1st SEMESTER
SQL> select sum(AMOUNT) FROM Deposit where ADATE<='01-JAN-96';
Output:-

5.List total deposit of customers living in city Nagpur


Query:-SQL> select sum(AMOUNT) FROM Deposit JOIN customer on
customer.CNAME=Deposit.CNAME where CITY='NAGPUR';
Output:-

6.List maximum deposit of customer living in Mumbai


Query:-SQL> select MAX(AMOUNT) FROM Deposit JOIN customer on
customer.CNAME=Deposit.CNAME where CITY='MUMBAI';
Output:-

7.List total deposit of cutomers having branch city Delhi


Query:-SQL> select sum(AMOUNT) FROM Deposit JOIN Branch on
Branch.BNAME=Deposit.BNAME where CITY='DELHI';

Output:-

8.List total deposit of customers living in city where Sunil is living.

NITIN KUMAR SINGAUR 33 | P a g e MCA – 1st SEMESTER


Query:-SQL> SELECT AMOUNT FROM DEPOSIT ,CUSTOMER WHERE
CUSTOMER.CNAME=DEPOSIT.CNAME AND CUSTOMER.CITY=(SELECT CITY
FROM CUSTOMER WHERE CNAME='ANIL');
Output:-

9.Count total number of Branch cities


Query:-SQL>select count(distinct CITY) from Branch;
Output:-

10.Count total number of Customer cities


Query:-SQL>select count(distinct CITY) from customer;
Output:-

11.Give branch name and branchwise deposit


Query:-SQL> SELECT BNAME,SUM(AMOUNT) FROM dEPOSIT GROUP BY BNAME;

NITIN KUMAR SINGAUR 34 | P a g e MCA – 1st SEMESTER


Output:-

12.Give city name and citywise deposit


Query:-SQL> SELECT CITY,SUM(AMOUNT) FROM DEPOSIT,CUSTOMER WHERE
CUSTOMER.CNAME=DEPOSIT.CNAME GROUP BY CUSTOMER.CITY;
Output:-

NITIN KUMAR SINGAUR 35 | P a g e MCA – 1st SEMESTER


13.Give citywise name and branchwise deposit
Query:-SQL>SELECT SUM(D.AMOUNT) FROM DEPOSIT D,BRANCH B WHERE
D.BNAME=B.BNAME GROUP BY D.BNAME,B.CITY;
Output:-

14.Give the branchwise deposit of customer after account date 1 Jan 96


Query:-SQL>select sum(AMOUNT) from Deposit where ADATE>'01JAN-96';
Output:-

15.Give branchwise loan of customer living in Nagpur


Query :-SQL>SELECT SUM(BR.AMOUNT) FROM BORROW BR,CUSTOMER C
WHERE C.CNAME=BR.CNAME AND C.CITY ='NAGPUR' GROUP BY BR.BNAME;
Output:-

NITIN KUMAR SINGAUR 36 | P a g e MCA – 1st SEMESTER


16.Count total number of Customers
Query :-SQL> select count(CNAME) from customer;
Output:-

17.Count total number of depositers branchwise


Query :-SQL> select count(distinct CNAME) from DEPOSIT GROUP BY BNAME;
Output:-

18.Give maximum loan from branch VRCE


Query :-SQL>SELECT MAX (AMOUNT) FROM borrow WHERE BNAME='VRCE';
Output:-

NITIN KUMAR SINGAUR 37 | P a g e MCA – 1st SEMESTER


19.Give living citywise loan of borrowers
Query :-SQL> SELECT SUM (AMOUNT) FROM borrow JOIN CUSTOMER ON
customer.CNAME=borrow.CNAME GROUP BY customer.CITY;
Output:-

20.Give the number of customers who are depositers as well as borrowers


Query :-SQL> SELECT COUNT (DISTINCT CNAME) FROM CUSTOMER WHERE
CNAME IN((SELECT CNAME FROM DEPOSIT) INTERSECT (SELECT CNAME
FROM BORROW));
Output:-

Assignment No. - 6
Group by and Having
1. List the branches having sum of deposit more than 50000
Query:- SQL> select BNAME from Deposit group by BNAME having
sum(AMOUNT)>5000;

Output:

NITIN KUMAR SINGAUR 38 | P a g e MCA – 1st SEMESTER


2. List the branch es having a sum of deposit more than 50000 and located
in city Mumbai
Query:- SQL> select Deposit.BNAME from Deposit,Branch where
Branch.BNAME=Deposit.BNAME and Branch.CITY='MUMBAI' group by Deposit.BNAME
having sum(AMOUNT)>5000;
Output:-

3.List the names of customers having deposit in the branches where the average deposit
is more than 50000
Query :-SQL> SELECT CNAME FROM DEPOSIT WHERE AMOUNT IN(SELECT
AVG(AMOUNT) FROM DEPOSIT)OR AMOUNT>5000;
Output:-

4.List the names of customers having maximum deposit


Query :-SQL> SELECT CNAME FROM DEPOSIT WHERE AMOUNT IN(SELECT MAX
(AMOUNT) FROM DEPOSIT);
Output:-

NITIN KUMAR SINGAUR 39 | P a g e MCA – 1st SEMESTER


5.List the names of customers having maximum deposit living in Nagpur
Query :-SQL> SELECT MAX(D.AMOUNT) FROM DEPOSIT D,CUSTOMER C WHERE
C.CNAME IN(SELECT CNAME FROM CUSTOMER WHERE CITY='NAGPUR')AND
C.CNAME=D.CNAME;
Output:-

6.List the names of branches having the highest number of depositer.


Query :- SELECT MAX(D.BNAME) FROM DEPOSIT D WHERE BNAME IN(SELECT
BNAME FROM Deposit );
Output:-

7.Count the number of depositors living in Nagpur


Query :-SQL> SELECT COUNT(D.CNAME) FROM DEPOSIT D JOIN CUSTOMER C
ON C.CNAME=D.CNAME WHERE C.CITY='NAGPUR';
Output:-

8. Give names of customers in VRCE branch having more deposit than all customer
from SB branch Andheri
Query :-SQL> SELECT D.CNAME FROM DEPOSIT D WHERE D.BNAME='VRCE'
AND D.AMOUNT > ALL ( SELECT MAX (DISTINCT D1.AMOUNT) FROM DEPOSIT
D1 WHERE D1.BNAME='ANDHERI');

NITIN KUMAR SINGAUR 40 | P a g e MCA – 1st SEMESTER


Output:-

9.Give names of customers in VRCE branch having more deposit than any other
customer in Andheri branch
Query :-SQL> SELECT CNAME FROM DEPOSIT WHERE AMOUNT > ALL (SELECT
AMOUNT FROM DEPOSIT WHERE BNAME='ANDHERI')AND BNAME='VRCE' ;
Output:-

10.Give names of customers having highest deposit in the branch where sunil is having
deposit
Query :-SQL>SELECT D1.CNAME FROM DEPOSIT D1, BRANCH B1 WHERE
D1.BNAME = B1.BNAME AND D1.AMOUNT >=ALL (SELECT D2.AMOUNT FROM
DEPOSIT D2, BRANCH B2 WHERE D2.CNAME ='SUNIL' AND D2.BNAME =
B2.BNAME AND B1.BNAME = B2.BNAME);
Output:-

NITIN KUMAR SINGAUR 41 | P a g e MCA – 1st SEMESTER


11.Give names of customers having highest deposit in the city where branch of Sunil is located
Query :-
SQL> SELECT D1.CNAME FROM DEPOSIT D1, BRANCH B1 WHERE D1.BNAME =
B1.BNAME AND D1.AMOUNT >=ALL (SELECT D2.AMOUNT FROM DEPOSIT D2,
BRANCH B2 WHERE D2.CNAME = 'SUNIL' AND D2.BNAME = B2.BNAME AND
B1.BNAME = B2.BNAME);
Output:-

12.Give names of customers having more deposit than the average deposit in their
respective branches.
Query :-SQL> SELECT D1.CNAME FROM DEPOSIT D1 WHERE D1.AMOUNT >= ALL
(SELECT AVG(D2.AMOUNT) FROM DEPOSIT D2 WHERE D1.BNAME = D2.BNAME
GROUP BY D2.BNAME);
Output:-

NITIN KUMAR SINGAUR 42 | P a g e MCA – 1st SEMESTER


13.Give names of customers having maximum deposit among deposits of Nagpur for branch
VRCE.
Query :-SQL> SELECT MAX(AMOUNT)FROM BORROW WHERE BNAME='VRCE';
Output:-

14.Give name of branch where number of depositers is more than 5.


Query :-SQL> SELECT BNAME FROM DEPOSIT GROUP BY BNAME HAVING
COUNT(CNAME)> 5;
Output:-

15.Give name of city having more customers living in than Nagpur


Query :-SQL> SELECT C.CITY FROM CUSTOMER C GROUP BY C.CITY HAVING
COUNT(C.CITY)> ALL(SELECT COUNT(C.CNAME) FROM CUSTOMER C WHERE
C.CITY='NAGPUR');
Output:-

NITIN KUMAR SINGAUR 43 | P a g e MCA – 1st SEMESTER


16.Give names of branches having the number of depositers more than the number of
borrowers.
Query :-SQL> SELECT D.BNAME FROM DEPOSIT D GROUP BY D.BNAME HAVING
COUNT(D.BNAME)>=ALL(SELECT COUNT(B.BNAME) FROM BORROW B GROUP
BY B.BNAME);
Output:-

17.Give the names of cities in which the maximum number of branches are located.
Query :-SQL> SELECT CITY FROM BRANCH GROUP BY CITY HAVING COUNT
(BNAME)>=ALL(SELECT COUNT(BNAME) FROM BRANCH GROUP BY CITY);
Output:-

18.Give the names of customers living in the city where the maximum number of
depositers are located
Query :-SQL> SELECT C.CITY FROM CUSTOMER C WHERE CITY IN(SELECT
C.CITY FROM DEPOSIT D,CUSTOMER C WHERE C.CNAME=D.CNAME GROUP BY
C.CITY HAVING COUNT(D.CNAME) >ALL(SELECT COUNT(D.CNAME) FROM
DEPOSIT D,CUSTOMER C WHERE C.CNAME=D.CNAME GROUP BY C.CITY));
Output:-

NITIN KUMAR SINGAUR 44 | P a g e MCA – 1st SEMESTER


19.Give the name of borrowers having the same branch city and highest borrowers.
Query:-SQL>SELECT B.CNAME FROM BORROW B WHERE B.BNAME IN(( SELECT
B1.BNAME FROM BORROW B1 GROUP BY B1.BNAME HAVING COUNT
(B.CNAME)>= ALL( SELECT COUNT (B1.CNAME) FROM BORROW B1 GROUP BY
B1.BNAME)));
Output:-

20.Count the number of customers living in the city where branch is located.

Query :-SQL> SELECT COUNT(CUSTOMER.CITY) FROM BRANCH,CUSTOMER WHERE


CUSTOMER.CITY=BRANCH.CITY;
Output:-

NITIN KUMAR SINGAUR 45 | P a g e MCA – 1st SEMESTER


Assignment No. - 7

The Update statement

1. Give 10% interest to all depositors


Query :- SQL>UPDATE DEPOSIT SET AMOUNT = AMOUNT+(AMOUNT*10)/100;
Output:-

2.Give 10% interest to all depositers having branch VRCE


Query :- SQL>UPDATE DEPOSIT SET AMOUNT=AMOUNT+AMOUNT*1.1 WHERE
BNAME=’VRCE
Output:-

NITIN KUMAR SINGAUR 46 | P a g e MCA – 1st SEMESTER


3.Give 10% interest to all depositers living in Nagpur
Query :- SQL>UPDATE DEPOSIT SET AMOUNT = AMOUNT *1.1 WHERE CNAME
IN(SELECT CNAME FROM CUSTOMER WHERE CITY='NAGPUR');
Output:-

4.Give 10% interest to all depositers living in Nagpur and having branch in city Mumbai.
Query :-SQL>UPDATE DEPOSIT SET AMOUNT=AMOUNT+(AMOUNT*10)/100
WHERE CNAME IN(SELECT CNAME FROM CUSTOMER WHERE CITY='NAGPUR')
AND BNAME IN(SELECT BNAME FROM BRANCH WHERE CITY='MUMBAI');
Output:-

NITIN KUMAR SINGAUR 47 | P a g e MCA – 1st SEMESTER


5.Add hundred rupees to the deposit of Anil and assign it to Sunil.
Query :-SQL> UPDATE DEPOSIT SET AMOUNT =(SELECT AVG(AMOUNT) FROM
DEPOSIT WHERE CNAME='ANIL')WHERE CNAME='SUNIL';
Output:-

6.Change the deposit of VRCE branch to 1000 and change the branch as VRCE- Ambazari
Query :-SQL>UPDATE DEPOSIT SET BNAME ='VRCE_AMBAZARI', AMOUNT=1000
WHERE BNAME='VRCE’;
Output:-

NITIN KUMAR SINGAUR 48 | P a g e MCA – 1st SEMESTER


7.Assign to the deposit of Anil the maximum deposit from VRCE branch
Query :-SQL> UPDATE DEPOSIT SET AMOUNT=( SELECT MAX(AMOUNT) FROM
DEPOSIT WHERE BNAME='VRCE') WHERE CNAME='ANIL';
Output:-

8.Change the living city of VRCE branch Borrowers to Nagpur.


Query :-SQL> UPDATE CUSTOMER SET CITY ='NAGPUR' WHERE CNAME
IN(SELECT CNAME FROM BORROW WHERE BNAME='VRCE');
Output:-

NITIN KUMAR SINGAUR 49 | P a g e MCA – 1st SEMESTER


9.Update deposit of Anil, give him maximum deposit from depositors in living city Nagpur
Query :-SQL> UPDATE DEPOSIT SET AMOUNT=( SELECT MAX(AMOUNT) FROM
DEPOSIT ,CUSTOMER WHERE DEPOSIT.CNAME=CUSTOMER.CNAME AND
CUSTOMER.CITY='NAGPUR') WHERE CNAME='ANIL';
Output:-

10.Deposit the sum of the deposits of Sunil and Vijay in the account of Anil.
Query :-SQL> UPDATE DEPOSIT SET AMOUNT=( SELECT SUM(AMOUNT) FROM
DEPOSIT WHERE CNAME IN('SUNIL','VIJAY')) WHERE CNAME='ANIL';
Output:-

NITIN KUMAR SINGAUR 50 | P a g e MCA – 1st SEMESTER


11.Transfer Rs. 500 from the account of Anil to the account of Sunil.
12.Transfer Rs. 500 from the account of Anil to the account of Sunil if both are
having the same branch.
Query :-SQL> UPDATE DEPOSIT SET AMOUNT =AMOUNT-500 WHERE
CNAME='ANIL' AND BNAME IN(SELECT D.BNAME FROM DEPOSIT D WHERE
D.CNAME='SUNIL');

Output:-

13.Transfer Rs. 10 from the account of Anil to the account of Sunil if both are living in Nagpur.
Query :-SQL> UPDATE DEPOSIT SET AMOUNT =AMOUNT-10 WHERE CNAME='ANIL'
AND CNAME IN(SELECT C.CNAME FROM CUSTOMER C CUSTOMER C1 WHERE
C1.CNAME='SUNIL' AND C.CITY ='NAGPUR' AND C.CITY=C1.CITY);

Output:-

NITIN KUMAR SINGAUR 51 | P a g e MCA – 1st SEMESTER


14.Transfer Rs. 10 from the account of Anil to the account of Sunil if they are living
in the same city.
Query :-SQL> UPDATE DEPOSIT SET AMOUNT =AMOUNT-10 WHERE CNAME='ANIL'
AND CNAME IN(SELECT C.CNAME FROM CUSTOMER C
,CUSTOMER C1 WHERE C1.CNAME='SUNIL' AND C.CITY=C1.CITY);
Output:-

15.Transfer Rs. 10 from the account of Anil to the account of Sunil if they are having
the same branches.
Query :-SQL> UPDATE DEPOSIT SET AMOUNT =AMOUNT- 10 WHERE
CNAME='ANIL' AND BNAME IN(SELECT D.BNAME FROM DEPOSIT D WHERE
D.CNAME='SUNIL');
Output:-

16.Add Rs. 1000 to the account of all those depositers who are having the highest deposit
amount in their respective branches.
Query :-SQL> UPDATE DEPOSIT SET AMOUNT=AMOUNT+1000 WHERE CNAME
IN( SELECT D.CNAME FROM DEPOSIT D GROUP BY D.BNAME,D.CNAME HAVING
AVG(D.AMOUNT)>=ALL(SELECT MAX(D1.AMOUNT) FROM DEPOSIT D1 WHERE
D.BNAME=D1.BNAME GROUP BY D1.BNAME));
Output:-

NITIN KUMAR SINGAUR 52 | P a g e MCA – 1st SEMESTER


17.Add Rs. 100 to the amount of all depositers having deposit higher than the
average deposit.
Query :-SQL> UPDATE DEPOSIT SET AMOUNT =AMOUNT+100 WHERE CNAME
IN(SELECT D.CNAME FROM DEPOSIT D GROUP BY D.CNAME HAVING
AVG(D.AMOUNT)> ALL( SELECT AVG(D1.AMOUNT) FROM DEPOSIT D1));
Output:-

18.Add Rs. 100 to the amount of all depositers having deposit higher than the average deposit
of their branch
Query :-SQL> UPDATE DEPOSIT SET AMOUNT=AMOUNT+100 WHERE AMOUNT
IN (SELECT AVG(AMOUNT) FROM DEPOSIT GROUP BY BNAME);

Output:-

NITIN KUMAR SINGAUR 53 | P a g e MCA – 1st SEMESTER


19.Add Rs. 100 to the amount of all customers living in the city where their branch is located.

Query :-SQL>UPDATE DEPOSIT SET AMOUNT=AMOUNT+100 WHERE CNAME


IN(SELECT D.CNAME FROM DEPOSIT D,BRANCH B,CUSTOMER C WHERE
B.BNAME=D.BNAME AND B.CITY=C.CITY AND C.CNAME=D.CNAME);

Output:-

20.Add Rs. 100 to the amount of all depositers having deposit higher than the average deposit
of their branch.
Query :-SQL> UPDATE DEPOSIT SET AMOUNT =AMOUNT+100 WHERE CNAME
IN(SELECT D.CNAME FROM DEPOSIT D GROUP BY D.CNAME HAVING
AVG(D.AMOUNT)> ALL( SELECT AVG(D1.AMOUNT) FROM DEPOSIT D1));
Output:-

NITIN KUMAR SINGAUR 54 | P a g e MCA – 1st SEMESTER


Assignment No. - 8
The Delete Statement

1. Delete branches having average deposit less than 5000


Query:-SQL> DELETE FROM BRANCH WHERE BNAME IN(SELECT BNAME FROM
DEPOSIT GROUP BY BNAME HAVING AVG(AMOUNT)<5000);
Output:-

2.Delete the branches having maximum loan more than 5000.


Query:-SQL> DELETE FROM BRANCH WHERE BNAME IN(SELECT BNAME FROM
BORROW GROUP BY BNAME HAVING MAX(AMOUNT)>5000);
Output:-

3.Delete branches of having deposit from Nagpur


Query:-SQL> DELETE FROM BRANCH WHERE BNAME IN (SELECT D.BNAME FROM
DEPOSIT D,CUSTOMER C WHERE D.CNAME=C.CNAME AND C.CITY='NAGPUR');
Output:-

4.Delete deposit of Anil and Sunil if both are having branch VIRAR.
Query:-SQL> DELETE FROM DEPOSIT WHERE CNAME IN('SUNIL','ANIL') AND
EXISTS (SELECT * FROM DEPOSIT D1,DEPOSIT D2 WHERE
D1.CNAME='ANIL'AND D2.CNAME='SUNIL'AND D1.BNAME=D2.BNAME AND
D1.BNAME='VIRAR');
Output:-

NITIN KUMAR SINGAUR 55 | P a g e MCA – 1st SEMESTER


5.Delete deposit of Anil and Sunil if both are having living city Nagpur
Query:-SQL> DELETE FROM CUSTOMER WHERE CNAME IN('ANIL','SUNIL') AND
CITY='NAGPUR';
Output:-

6.Delete deposit of Anil and Sunil if both are having same living city.
Query:-SQL> DELETE FROM DEPOSIT WHERE CNAME IN ('ANIL','SUNIL')AND EXISTS
(SELECT* FROM CUSTOMER C,CUSTOMER C1 WHERE C.CNAME='ANIL' AND
C1.CNAME='SUNIL' AND C.CITY=C1.CITY);
Output:-

7.Delete deposit of Anil and Sunil if both are having less deposit than Vijay
Query:-SQL> DELETE FROM DEPOSIT WHERE CNAME IN('ANIL','SUNIL') AND
EXISTS( SELECT * FROM DEPOSIT D,DEPOSIT D1 WHERE D.CNAME
IN('ANIL','SUNIL') AND D1.CNAME='VIJAY' AND D.AMOUNT< D1.AMOUNT);
Output:-

8.Delete deposit of vijay.


Query:-SQL> DELETE FROM DEPOSIT WHERE CNAME='VIJAY';
Output:-

NITIN KUMAR SINGAUR 56 | P a g e MCA – 1st SEMESTER


9.Delete customer from Bombay City.
Query:-SQL> DELETE FROM CUSTOMER WHERE CITY='BOMBEY';
Output:-

10.Delete depositer if the branch is VIRAR and depositer name is Ajay.


Query:-SQL> DELETE FROM DEPOSIT WHERE BNAME='VIRAR' AND CNAME='AJAY';
Output:-

11.Delete depositer having deposit less than 5000


Query:-SQL> DELETE FROM DEPOSIT WHERE AMOUNT<5000;
Output:-

12.Delete borrower having loan more than 1000 and branch Karolbagh
Query:-SQL> DELETE FROM BORROW WHERE AMOUNT>1000 AND BNAME
IN(SELECT BNAME FROM BRANCH WHERE BNAME='KAROLBAGH');
Output:-

13.Delete the names of those depositers of VRCE branch who live in city Bombay
Query:-SQL> DELETE FROM DEPOSIT WHERE BNAME ='VRCE' AND CNAME IN(
SELECT CNAME FROM CUSTOMER WHERE CITY='BOMBAY');
Output:-

NITIN KUMAR SINGAUR 57 | P a g e MCA – 1st SEMESTER


Assignment No. 9

1.Create the Tables according to the following Definition -

Table STUDENT
NAME VARCHAR(20)
CLASS VARCHAR(20)
ROLLNO NUMBER(10) PRIMARY KEY
AGE NUMBER(10)
CITY VARCHAR(20)
DOB DATE
MOB NUMBER(10)

Query:- SQL> create table STUDENT(NAME VARCHAR(20),CLASS VARCHAR(20),ROLLNO


NUMBER(10) PRIMARY KEY,AGE NUMBER(10),CITY VARCHAR(20),DOB DATE, MOB
NUMBER(10));
Output:-

Table BOOK
ACNO NUMBER(10)
BOOK_NAME VARCHAR(20)
AUTHOR VARCHAR(20)
PUBLISHER VARCHAR(20)
PRICE NUMBER
YEAR_OF_PUBLICATION DATE

Query:- SQL> create table BOOK(ACNO NUMBER(10),BOOK_NAME


VARCHAR(20),AUTHOR VARCHAR(20),PUBLISHER VARCHAR(20),PRICE NUMBER,
YEAR_OF_PUBLICATION DATE);

Output:-

NITIN KUMAR SINGAUR 58 | P a g e MCA – 1st SEMESTER


Table BOOK_ISSUE
CARD_NO VARCHAR(20)
ACNO NUMBER
DATE_OF_ISSUE DATE
RETURN_DATE DATE

Query:- SQL> create table BOOK_ISSUE(CARD_NO VARCHAR(20),ACNO


NUMBER,DATE_OF_ISSUE DATE,RETURN_DATE DATE);

Output:-

Table DEPARTMENT
DPT_NO NUMBER PRIMARY KEY
DPT_NAME VARCHAR(20)
HOD VARCHAR(20)
PHONE_NO NUMBER

Query:- SQL> create table DEPARTMENT(DPT_NO NUMBER PRIMARY KEY,DPT_NAME


VARCHAR(20),HOD VARCHAR(20),PHONE_NO NUMBER);
Output:-

NITIN KUMAR SINGAUR 59 | P a g e MCA – 1st SEMESTER


Table EMPLOYEE
EMPNO NUMBER PRIMARY KEY
ENAME VARCHAR(20)
ECITY VARCHAR(20)
SALARY NUMBER
DELEGATION VARCHAR(20)
DPT_NO NUMBER FOREIGN KEY
DPT_NAME VARCHAR(20)

Query:- :- SQL> create table EMPLOYEE(EMPNO NUMBER PRIMARY KEY,ENAME


VARCHAR(20),ECITY VARCHAR(20),SALARY NUMBER,DELEGATION
VARCHAR(20),DPT_NO NUMBER ,FOREIGN KEY(DPT_NO) REFERENCES
DEPARTMENT(DPT_NO) ,DEPT_NAME VARCHAR(20));
Output:-

Table SUPPLIER
SUP_ID VARCHAR(3) PRIMARY KEY
SUP_NAME VARCHAR(20)
SUP_ADDRESS VARCHAR(20)

Query:- SQL> create table SUPPLIER(SUP_ID VARCHAR(3) PRIMARY KEY,SUP_NAME


VARCHAR(20),SUP_ADDRESS VARCHAR(20));
Output:-

NITIN KUMAR SINGAUR 60 | P a g e MCA – 1st SEMESTER


Table SUPPLY
SUP_ACNO NUMBER PRIMARY KEY
SUP_ID VARCHAR(3) NOT NULL REFERENCE KEY
PRICE FLOAT(7,2)>1500
SUP_DATE DATE
Query:- SQL> create table SUPPLY(SUP_ACNO NUMBER PRIMARY KEY,SUP_ID
VARCHAR(3) NOT NULL,FOREIGN KEY(SUP_ID) REFERENCES SUPPLIER(SUP_ID)
,PRICE FLOAT(72),SUP_DATE DATE);
Output:-

➢ Update the STUDENT TABLE according to following definition.


NAME VARCHAR(20)
FATHER_NAME VARCHAR(20)
CLASS VARCHAR(20)
ROLLNO NUMBER(10) PRIMARY KEY
AGE NUMBER(10)
CITY VARCHAR(20)
DOB DATE
PH_NO NUMBER
DPT_NO NUMBER FOREIGN KEY

Query:-

Output:-

NITIN KUMAR SINGAUR 61 | P a g e MCA – 1st SEMESTER


2.Describe tables which are already created.
Query:- SQL> DESC STUDENT;

Output:-

Query:- SQL> DESC BOOK;


Output:-

Query:- SQL> DESC BOOK_ISSUE;


Output:-

NITIN KUMAR SINGAUR 62 | P a g e MCA – 1st SEMESTER


Query:- SQL> DESC DEPARTMENT;
Output:-

Query:- SQL> DESC EMPLOYEE;


Output:-

Query:- SQL> DESC SUPPLIER;


Output:-

NITIN KUMAR SINGAUR 63 | P a g e MCA – 1st SEMESTER


Query:- SQL> DESC SUPPLY;
Output:-

Assignment No. 10

1. Find the name of the books which published in the 2020.

Query:- SQL> SELECT BOOK_NAME FROM BOOK WHERE YEAR_OF_PUBLICATION>='01-


JAN-2020'AND YEAR_OF_PUBLICATION<='30-DEC-2020';
Output:-

NITIN KUMAR SINGAUR 64 | P a g e MCA – 1st SEMESTER


2.Find the name of the books which publish by TATA MEGHAI.
Query:- SQL> SELECT BOOK_NAME FROM BOOK WHERE PUBLISHER='TATA MEGHAI';

Output:-

3.Find the name of the student whose age greater then 18.
Query:- SQL> SELECT NAME FROM STUDENT WHERE AGE>18;

Output:-

4.Find the name of the student who live in durg.

Query:- SQL> SELECT NAME FROM STUDENT WHERE CITY='DURG';


Output:-

NITIN KUMAR SINGAUR 65 | P a g e MCA – 1st SEMESTER


5.Find the account no of the books with issue on 10 december 2020.

Query:- SQL> SELECT ACNO FROM BOOK_ISSUE WHERE DATE_OF_ISSUE='10-DEC-2020';


Output:-

6.Find the name of the books which price are greater then 10000.

Query:- SELECT BOOK_NAME FROM BOOK WHERE PRICE>10000;


Output:-

7.Find the name of the students who is student of the MCA 1st semester.
Query:- SQL> SELECT NAME FROM STUDENT WHERE CLASS='MCA1st';
Output:-

NITIN KUMAR SINGAUR 66 | P a g e MCA – 1st SEMESTER


8.Find the name of the books in descending order.
Query:- SQL> SELECT*FROM BOOK ORDER BY BOOK_NAME DESC;
Output:-

NITIN KUMAR SINGAUR 67 | P a g e MCA – 1st SEMESTER


9.Find the book account no which issue card no BC1694.
Query:- SQL> SELECT ACNO FROM BOOK_ISSUE WHERE CARD_NO='BC1694';
Output:-

10.Delete the record of the books which price are greater then 5000.
Query:- SQL> DELETE FROM BOOK WHERE PRICE>5000;
Output:-

NITIN KUMAR SINGAUR 68 | P a g e MCA – 1st SEMESTER


Assignment No :- 11

1. Find the name of the student whose living in durg and age is greater then 35.

Query :- SQL> select NAME from student where city='durg' AND age>35;

Output ;-

2. Select student name from student table where city is durg and age is greater then 35.

Query :- SQL> select NAME from student where city='durg'AND age>35;

Output :-

3. Find the name of the all student who lived in the bilashpur and age is less then 18.

Query :- SQL> select NAME from student where city='bilashpur'AND age<18;

Output :-

NITIN KUMAR SINGAUR 69 | P a g e MCA – 1st SEMESTER


4. Find the student name from student table where city is bhilai.
Query:- SQL> select NAME from student where city='bhilai';
Output :-

5. Find the name of the books which publish in the 2020 and price are greater and equal to 500.
Query :- SQL> select BOOK_NAME from book where YEAR_OF_PUBLICATION BETWEEN '01-JAN-
2020' AND '31-DEC-2020' AND price>=500;
Output :-

NITIN KUMAR SINGAUR 70 | P a g e MCA – 1st SEMESTER


6. Find the name of the book with year of publication in a ascending order.
Query :- SQL> select*from book ORDER BY BOOK_NAME ASC;
Output:-

NITIN KUMAR SINGAUR 71 | P a g e MCA – 1st SEMESTER


7. Find the detail of all books of descending order of the book name.
Query :- SQL> select*from book ORDER BY BOOK_NAME DESC;
Output :-

NITIN KUMAR SINGAUR 72 | P a g e MCA – 1st SEMESTER


8. Find the detail of all student whose not belonging from Raipur.
Query :- SQL> select*from student where CITY!= 'raipur';
Output :-

NITIN KUMAR SINGAUR 73 | P a g e MCA – 1st SEMESTER


9. Find the name of the student whose city is Raipur but age is not 20.
Query :- SQL> select NAME from student where CITY='raipur' AND AGE!=20;
Output :-

10. Find the name of the student where city is the descending order.
Query :- SQL> select NAME from student ORDER BY CITY DESC;
Output :-

NITIN KUMAR SINGAUR 74 | P a g e MCA – 1st SEMESTER


11. Find the name of the all student who studying in MCA 1st and not living in durg.
Query :- SQL> select NAME from student where CLASS= 'MCA1st' and CITY!='durg';
Output :-

12. Find the detail of the student who is greater than 01-JAN-2000.
Query :- SQL> select*from student where DOB>'01-JAN-2000';
Output :-

NITIN KUMAR SINGAUR 75 | P a g e MCA – 1st SEMESTER


13. Find the NAME , CITY, AGE , CLASS of student whose mobile number is 9828714025.
Query :- SQL> select NAME,CITY,AGE, CLASS from student where MOB=9828714025;
Output :-

Assignment No.12
1. Find the account no of all books which issue on 10-Mar-2021.
Query :- SQL> select ACNO from book_issue where DATE_OF_ISSUE='10-MAR-2021';
Output :-

2. Find the detail of all books published by the TATA MAIGHAI.


Query :- SQL> select*from BOOK where PUBLISHER='tata maighai';
Output :-

NITIN KUMAR SINGAUR 76 | P a g e MCA – 1st SEMESTER


3. Find the detail of books where year of publication 2021 publisher tata maighai and subject is compiler
design.
Query :- SQL> select*from BOOK where PUBLISHER='tata maighai'AND BOOK_NAME='compiler design';

Output :-

4. Find the name of the book which year of publication not in a 2022 and the publisher is the PHP or
TATA MAIGHAI.
Query :- SQL> select BOOK_NAME from BOOK where YEAR_OF_PUBLICATION!='01-01-2022' AND
PUBLISHER= 'PHP'OR PUBLISHER='tata maighai';

Output :-

5. Find the name of the all students whose class is MCA 3rd and city is Raipur or Bhilai.
Query :- SQL> select NAME from student where CLASS='mca3rd' AND (CITY='raipur' OR CITY='bhilai');

Output :-

NITIN KUMAR SINGAUR 77 | P a g e MCA – 1st SEMESTER


6. Find the detail of all students whose city bhilai or durg and age 20 arrenge in the name wise.
Query :- SQL> select*from student where AGE=20 AND (CITY='bhilai' OR CITY='durg');
Output :-

7. Find the detail of all student whose age is descending order.


Query :- SQL> select*from student ORDER BY AGE DESC;
Output :-

NITIN KUMAR SINGAUR 78 | P a g e MCA – 1st SEMESTER


8. Find the detail of all books which issued on 10 september 2022.
Query :- SQL> select*from book_issue where DATE_OF_ISSUE='10-sep-2022';
Output :-

9. Select account no.book , bname.book , price.book.


Query :- SQL> select ACNO ,BOOK_NAME ,PRICE from book;
Output :-

NITIN KUMAR SINGAUR 79 | P a g e MCA – 1st SEMESTER


PL\SQL

NITIN KUMAR SINGAUR 80 | P a g e MCA – 1st SEMESTER


1. Write a program in PL/SQL program to print series of Sin x.
Coding:
DECLARE
n INTEGER;
i INTEGER;
j INTEGER;
BEGIN
DBMS_OUTPUT.PUT_LINE('9 terms sin(x) series');
n := 9;
DBMS_OUTPUT.PUT_LINE('sin(x) = x');
j := 1;
FOR i IN 2..n LOOP
IF MOD(i, 2) = 0 THEN
j := j + 2;
DBMS_OUTPUT.PUT_LINE('+(x^' || j || '/' || j || '!)');
ESLE
j := j + 2;
DBMS_OUTPUT.PUT_LINE('-(x^' || j || '/' || j || '!)');
END IF;
IF j = n OR j + 1 = n THEN
EXIT;
END IF;
END LOOP;
END;
/

Output:-

NITIN KUMAR SINGAUR 81 | P a g e MCA – 1st SEMESTER


2. Write a program in PL/SQL program to print series of cos x.
Coding:

DECLARE
n INTEGER;
i INTEGER;
j INTEGER;
BEGIN
DBMS_OUTPUT.PUT_LINE('9 terms cos(x) series');
n := 9;
j := 1;
DBMS_OUTPUT.PUT_LINE('cos(x) = ' || j);
j := j - 1;
FOR i IN 2..n LOOP
IF MOD(i, 2) = 0 THEN
j := j + 2;
DBMS_OUTPUT.PUT_LINE('-(x^' || j || '/' || j || '!)');
ESLE
j := j + 2;
DBMS_OUTPUT.PUT_LINE('+(x^' || j || '/' || j || '!)');
END IF;
IF j = n OR j + 1 = n THEN
EXIT;
END IF;
END LOOP;
END;
/

Output :-

NITIN KUMAR SINGAUR 82 | P a g e MCA – 1st SEMESTER


3. Write a program in PL/SQL program to print the series of the Tan x.
Coding:-
declare
sum1 number(6,5) :=0;
degree number(5,2);
x number(5,2);
term number(6,5) :=0;
num number(6,5);
m integer :=1;
i integer :=3;
j integer :=1;
begin
dbms_output.put_line('Path: tanx.sql');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 06/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
degree := &degree;
x := degree*(3.142/180);
num := x;
term := num/m;
sum1 := sum1 +term;
num := num*x*x;
m := m*i;
i := i+2;
while(abs(term)>=0.00001)
loop
term := (j*num)/m;
sum1 := sum1 +term;
num := num*x*x;
m := m*i;
i := i+2;
j := j+1;
end loop;
dbms_output.put_line('tan('||degree||') : '||sum1);
end;
/

Output:-

NITIN KUMAR SINGAUR 83 | P a g e MCA – 1st SEMESTER


4. Write a program in PL/SQL program to print series of Log x.
Coding :-
DECLARE
n INTEGER;
i INTEGER;
BEGIN
DBMS_OUTPUT.PUT_LINE('log(x) series is');
n := 9;
dbms_output.put_line('Entered terms = '||n);
DBMS_OUTPUT.PUT_LINE('log(x+1) = x');
FOR i IN 2..n LOOP
IF MOD(i, 2) = 0 THEN
DBMS_OUTPUT.PUT_LINE('-(x^' || i || '/' || i || ')');
ESLE
DBMS_OUTPUT.PUT_LINE('+(x^' || i || '/' || i || ')');
END IF;
END LOOP;
END;
/
Output:-

NITIN KUMAR SINGAUR 84 | P a g e MCA – 1st SEMESTER


5. Write a program in PL/SQL program to print the series of ex .
Coding :-
DECLARE
n INTEGER;
i INTEGER;
BEGIN
n := 9;
DBMS_OUTPUT.PUT_LINE('9 term e^x series');
i := 1;
DBMS_OUTPUT.PUT_LINE('e^x = ' || i);
FOR i IN 1..n LOOP
DBMS_OUTPUT.PUT_LINE('+(x^' || i || '/' || i || '!)');
END LOOP;
END;
/

Outpput :-

6. Write a program in PL/SQL program to print the series of Even Number 1 to 10.
Coding :-

NITIN KUMAR SINGAUR 85 | P a g e MCA – 1st SEMESTER


6.Write a program in PL/SQL program to print the series of Even Number 1 to 10.
Coding :-

declare
num integer;
begin
dbms_output.put_line('Path: even.sql');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 07/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
dbms_output.put_line('even number series :');
for num in 1..10
loop
if mod(num,2)=0
then
dbms_output.put_line(num);
end if;
end loop;
end;
/

Output :-

NITIN KUMAR SINGAUR 86 | P a g e MCA – 1st SEMESTER


7. Write a program in PL/SQL program to reverse a Even Number 1 to 50.
Coding :-
declare
x number :=0;
begin
dbms_output.put_line('Path: reverse.sql');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 07/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
dbms_output.put_line('reverse even number 1 to 50 :');
for x in reverse 1..50
loop
if mod(x,2)=0
then
dbms_output.put_line(x);
end if;
end loop;
end;
/

Output :-

NITIN KUMAR SINGAUR 87 | P a g e MCA – 1st SEMESTER


8. Write a program in PL/SQL program to print the series of Odd Number 300 to 350.
Coding :-
declare
num integer;
begin
dbms_output.put_line('Path:odd.sql');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 07/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
dbms_output.put_line('odd number series :');
for num in 300..350
loop
if mod(num,2)=1
then
dbms_output.put_line(num);
end if;
end loop;
end;
/

Output :-

NITIN KUMAR SINGAUR 88 | P a g e MCA – 1st SEMESTER


9. Write a program in PL/SQL program to Find Greatest among Three Numbers.
Coding :-
declare
num1 integer;
num2 integer;
num3 integer;
begin
dbms_output.put_line('Path: greatest.sql');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 07/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
num1 := &num1;
num2 := &num2;
num3 := &num3;
if(num1>num2) and (num1>num3) then
dbms_output.put_line(num1||' is greatest number');
else if (num2>num3) then
dbms_output.put_line(num2||' is greatest number');
else
dbms_output.put_line(num3||' is greatest number');
end if;
end if;
end;
/

Output :-

NITIN KUMAR SINGAUR 89 | P a g e MCA – 1st SEMESTER


10. Write a program in PL/SQL program to Find minimum among Three Numbers.
Coding :-
declare
num1 integer;
num2 integer;
num3 integer;
begin
dbms_output.put_line('Path: minimum.sql');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 07/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
num1 := &num1;
num2 := &num2;
num3 := &num3;
if(num1<num2) and (num1<num3) then
dbms_output.put_line(num1||' is minimum number');
else if (num2<num3) then
dbms_output.put_line(num2||' is minimum number');
else
dbms_output.put_line(num3||' is minimum number');
end if;
end if;
end;
/

Output :-

NITIN KUMAR SINGAUR 90 | P a g e MCA – 1st SEMESTER


11. Write a program in PL/SQL program to Find Leap Year.
Coding :-
declare
year1 number(4);
begin
dbms_output.put_line('Path: leap.sql');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 07/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
year1 := &year1;
if mod(year1,400)=0
then
dbms_output.put_line(year1||' is a leap year ');
else if mod(year1,100)=0
then
dbms_output.put_line(year1||' is not a leap year ');
else if mod(year1,4)=0
then
dbms_output.put_line(year1||' is a leap year ');
else
dbms_output.put_line(year1||' is not a leap year ');
end if;
end if;
end if;
end;
/

Output :-

NITIN KUMAR SINGAUR 91 | P a g e MCA – 1st SEMESTER


12. Write a program in PL/SQL program to print the series of 1,2,4,…………,512.
Coding :-
declare
n1 integer :=1;
n2 integer :=0;
i integer;
begin
dbms_output.put_line('Path: series.sql');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 07/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
dbms_output.put_line(n1);
for i in n1..9
loop
n2 := n1 * 2;
dbms_output.put_line(n2);
n1 := n2;
end loop;
end;
/

Output :-

NITIN KUMAR SINGAUR 92 | P a g e MCA – 1st SEMESTER


13. Write a program in PL/SQL program for Fibonacci Series.
Coding:-
declare
n1 integer := 1;
n2 integer := 2;
n3 integer := 0;
i integer;
num integer;
begin
dbms_output.put_line('Path: Fibo');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 07/01/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
num := &num;
dbms_output.put_line('fibonacci series is up to '||num);
dbms_output.put_line(n1);
dbms_output.put_line(n2);
for i in 3..num loop
n3 := n1+n2;
dbms_output.put_line(n3);
n1 := n2;
n2 := n3;
end loop;
end;
/

Output :-

NITIN KUMAR SINGAUR 93 | P a g e MCA – 1st SEMESTER


14. Write a PL/SQL program to arrange the number of two variable in such a way that
the small number will store in num_small variable and large number will store in
num_large variable.
Coding:
declare
var1 number;
var2 number;
num_samll number;
num_large number;
begin
dbms_output.put_line('Path: arrang.sql');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 18/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
var1 := &var1;
var2 := &var2;
if(var1>var2)
then
num_large := var1;
num_samll := var2;
else
num_large := var2;
num_samll := var1;
end if;
dbms_output.put_line('num_samll : '||num_samll);
dbms_output.put_line('num_large : '||num_large);
end;
/

Output:-

NITIN KUMAR SINGAUR 94 | P a g e MCA – 1st SEMESTER


15. Write a PL/SQL procedure to calculate the incentive on a target achieved and
display the message either the record updated or not.
Coding:-
DECLARE
e empdev.eid%type :='&employee_id';
sal empdev.salary%type;
target_qty number;
PROCEDURE calculate_incentive (
sal_achieve NUMBER,
target NUMBER,
emp_id NUMBER
)
IS
incentive NUMBER := 0;
updated VARCHAR2(3) := 'No';
BEGIN
IF sal_achieve > (target + 200) THEN
incentive := (sal_achieve - target)/4;

UPDATE empdev
SET salary = salary + incentive
WHERE eid= emp_id;

updated := 'Yes';
END IF;

DBMS_OUTPUT.PUT_LINE (
'Table updated? ' || updated || ', ' ||
'incentive = ' || incentive || '.'
);
END calculate_incentive;
BEGIN
dbms_output.put_line('Author : Nitin Kumar Singaur');
dbms_output.put_line('Date:- 20/12/2022 ');
dbms_output.put_line('MCA-I SEMESTER');
dbms_output.put_line('Unit - v');
select salary into sal from empdev where eid=e;
target_qty := &target_qty;
calculate_incentive(sal, target_qty, e);
END;
/

NITIN KUMAR SINGAUR 95 | P a g e MCA – 1st SEMESTER


Output:

NITIN KUMAR SINGAUR 96 | P a g e MCA – 1st SEMESTER


16. Write a PL/SQL program to check whether a number is even or odd.
Coding:
declare
num number;
begin
dbms_output.put_line('Path: pro15');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 20/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
num := &num;
if mod(num,2)=0
then
dbms_output.put_line(num||' is even number');
else
dbms_output.put_line(num||' is odd number');
end if;
end;
/

Output:-

NITIN KUMAR SINGAUR 97 | P a g e MCA – 1st SEMESTER


17. Write a PL/SQL program to check whether a date falls on weekend i.e. SATURDAY
or SUNDAY.
Coding:
declare
v_date date := to_date('&new_date','DD-MM-YY');
v_day varchar2(12);
begin
dbms_output.put_line('Path: pro16');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 20/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
v_day := RTRIM(TO_CHAR(v_date, 'day'));
if v_day in ('saturday','sunday')
THEN
dbms_output.put_line('day of the '||v_date||' is '||v_day||' and it is fall in the weekend');
else
dbms_output.put_line('day of the '||v_date||' is '||v_day||' and it is not fall in the weekend');
end if;
end;
/

Output:-

NITIN KUMAR SINGAUR 98 | P a g e MCA – 1st SEMESTER


18. Write a PL/SQL program to display the description against a grade
Coding:-
declare
grade char(1);
begin
dbms_output.put_line('Path: pro17');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 20/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
grade := '&grade';
if grade = 'A' then
dbms_output.put_line('your grade is : Outstanding');
elsif grade = 'B' then
dbms_output.put_line('your grade is : Execilent');
elsif grade = 'C' then
dbms_output.put_line('your grade is : very Good');
elsif grade = 'D' then
dbms_output.put_line('your grade is : Average');
elsif grade = 'E' then
dbms_output.put_line('your grade is : Poor');
else
dbms_output.put_line('you entered wrong grade');
end if;
end;
/

Output:-

NITIN KUMAR SINGAUR 99 | P a g e MCA – 1st SEMESTER


19. Write a PL/SQL program to display the description against a grade using CASE
statement.
Coding:
declare
grade char(1);
begin
dbms_output.put_line('Path: grade ');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 20/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
grade := '&grade';
case grade
when 'A' then
dbms_output.put_line('your grade is : Outstanding');
when 'B' then
dbms_output.put_line('your grade is : Execilent');
when 'C' then
dbms_output.put_line('your grade is : very Good');
when 'D' then
dbms_output.put_line('your grade is : Average');
when 'E' then
dbms_output.put_line('your grade is : Poor');
else
dbms_output.put_line('you entered wrong grade');
end case;
end;
/
Output:-

NITIN KUMAR SINGAUR 100 | P a g e MCA – 1st SEMESTER


20. Write a PL/SQL program to display the description against a grade using CASE
statement with EXCEPTION.
Coding:-
declare
grade char(1);
begin
dbms_output.put_line('Path: pro19');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 020/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
grade := '&grade';
case grade
when 'A' then
dbms_output.put_line('your grade is : Outstanding');
when 'B' then
dbms_output.put_line('your grade is : Execilent');
when 'C' then
dbms_output.put_line('your grade is : very Good');
when 'D' then
dbms_output.put_line('your grade is : Average');
when 'E' then
dbms_output.put_line('your grade is : Poor');
end case;
exception
when case_not_found then
dbms_output.put_line('you entered wrong grade');
end;
/
Output:-

NITIN KUMAR SINGAUR 101 | P a g e MCA – 1st SEMESTER


21. Write a PL/SQL program to check whether a given number is positive, negative or
zero.
Coding:-
declare
num number;
begin
dbms_output.put_line('Path: pro20');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 20/12/2022 ');
dbms_output.put_line('unit:- V ');
num := &num;
if num > 0
then
dbms_output.put_line(num||' is a positive number');
elsif num < 0
then
dbms_output.put_line(num||' is a negative number');
else
dbms_output.put_line('Entered number '||num||' is zero');
end if;
end;
/

Output:-

NITIN KUMAR SINGAUR 102 | P a g e MCA – 1st SEMESTER


22. Write a PL/SQL program to check whether a given character is letter or digit.
Coding:-
declare
v_char char(1);
begin
dbms_output.put_line('Path: pro21');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 20/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
v_char := '&check_char';
IF ( v_char >= 'A'
AND v_char<= 'Z' )
OR (v_char >= 'a'
AND v_char <= 'z' ) THEN
dbms_output.put_line('Entered charecter '||v_char||' is a letter');
else
dbms_output.put_line('Entered charecter '||v_char||' is not a letter');
IF v_char BETWEEN '0' AND '9' THEN
dbms_output.put_line('Entered charecter '||v_char||' is a digit');
else
dbms_output.put_line('Entered charecter '||v_char||' is not a digit');
end if;
end if;
end;
/
Output:-

NITIN KUMAR SINGAUR 103 | P a g e MCA – 1st SEMESTER


23. Write a PL/SQL program to convert a temperature in scale Fahrenheit to Celsius
and vice versa.
Coding:-
declare
temp_c number(5,2) := '&temprature_in_Celsius';
temp_f number(5,2) := '&temprature_in_Fahrenheit';
f number(5,2);
c number(5,2);
begin
dbms_output.put_line('Path: pro22');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 20/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
f := temp_c * (9 / 5) + 32;
dbms_output.put_line('========================================');
dbms_output.new_line();
dbms_output.put_line(temp_c||' Celsius = '||f||' Fahrenheit');
c := (temp_f - 32) * (5 / 9);
dbms_output.put_line(temp_f||' Fahrenheit = '||c||' Celsius');
end;
/

Output:-

NITIN KUMAR SINGAUR 104 | P a g e MCA – 1st SEMESTER


24. Write a PL/SQL program to print the value of a variable inside and outside a loop
using LOOP EXIT statement.
Coding:
declare
var number;
begin
dbms_output.put_line('Path: pro23');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 20/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
var := &var;
dbms_output.put_line('value outside of the loop is : ');
dbms_output.put_line('var = '||var);
dbms_output.new_line;
dbms_output.put_line('value intside of the loop is : ');
loop
var := var + 10;
dbms_output.put_line('var = '||var);
if var > 50 then
exit;
end if;
end loop;
dbms_output.new_line;
dbms_output.put_line('value after exit from the loop is : ');
dbms_output.put_line('var = '||var);
end;
/

Output:-

NITIN KUMAR SINGAUR 105 | P a g e MCA – 1st SEMESTER


25. Write a program in PL/SQL to show the uses of nested loop.
Coding:
declare
i number;
j number;
begin
dbms_output.put_line('Path: pro24');
dbms_output.put_line('Author:- Nitin Kumar Sinagur');
dbms_output.put_line('Date:- 20/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
for i in 0..2 loop
for j in 0..2 loop
if j = i then
dbms_output.put_line('i = '||i||' , j = '||j);
end if;
end loop;
end loop;
end;
/
Output:-

NITIN KUMAR SINGAUR 106 | P a g e MCA – 1st SEMESTER


26. Write a program in PL/SQL using nested loop with EXIT WHEN statement.
Coding:-
declare
i number;
j number;
begin
dbms_output.put_line('Path: pro25');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 20/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
for i in 0..2 loop
for j in 0..2 loop
exit when j = i;
dbms_output.put_line('i = '||i||' , j = '||j);
end loop;
end loop;
end;
/
Output:-

NITIN KUMAR SINGAUR 107 | P a g e MCA – 1st SEMESTER


27. Write a program in PL/SQL using loop with CONTINUE statement.
Coding:-
declare
i number;
begin
dbms_output.put_line('Path: pro26');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 20/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
for i in 0..10
loop
continue when (i = 5);
dbms_output.put_line('loop index : '||i);
end loop;
end;
/
Output:-

NITIN KUMAR SINGAUR 108 | P a g e MCA – 1st SEMESTER


28. Write a program in PL/SQL to print 1st n number.
Coding:-
declare
n number;
begin
dbms_output.put_line('Path: pro27');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 20/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
n := &n;
dbms_output.put_line('1st '||n||' numbers are : ');
for i in 1..n
loop
dbms_output.put_line(i);
end loop;
end;
/
Output:-

NITIN KUMAR SINGAUR 109 | P a g e MCA – 1st SEMESTER


29. Write a program in PL/SQL to print 1st n number with difference of 3 and starting
from 1. Coding:
declare
n number;
i number;
j number := 1;
begin
dbms_output.put_line('Path: pro28');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
n := &n;
dbms_output.put_line('1st '||n||' numbers with difference of 3 are : ');
dbms_output.put_line(j);
for i in 1..n-1
loop
j := j + 3;
dbms_output.put_line(j);
end loop;
end;
/

Output:-

NITIN KUMAR SINGAUR 110 | P a g e MCA – 1st SEMESTER


30. Write a program in PL/SQL to print the prime number between 1 to 50.
Coding:
declare
i integer;
j integer;
counter integer := 0;
begin
dbms_output.put_line('Path: pro29');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
dbms_output.put_line('prime numbers up to 1 to 50 are : ');
for i in 2..50 loop
for j in 1..i loop
if mod(i,j)=0 then
counter := counter + 1;
end if;
end loop;
if counter = 2 then
dbms_output.put_line(i);
end if;
counter := 0;
end loop;
end;
/

Output:-

NITIN KUMAR SINGAUR 111 | P a g e MCA – 1st SEMESTER


31. Write a program in PL/SQL to insert record from one table to another.
Coding:
drop table player;
create table player(position number(3),name varchar2(14),best number(3));
insert into player values(1,'Rohit',170);
insert into player values(2,'Virat',250);
insert into player values(3,'KL Rahul',175);
insert into player values(4,'Dhawan',120);
insert into player values(5,'Dhoni',100);
insert into player values(6,'Hardik',80);
commit;
drop table ODI_player;
create table ODI_player(position number(3),name varchar2(14),best number(3));
declare
cursor cur_insert
is
select position,name,best from player;
prank player.position%type;
pname player.name%type;
pbest player.best%type;
i number;
begin
dbms_output.put_line('Path: pro30');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
if not cur_insert%isopen
then
open cur_insert;
end if;
loop
fetch cur_insert into prank,pname,pbest ;
insert into ODI_player(position,name,best)values(prank,pname,pbest);
exit when cur_insert%notfound;
end loop;
i := cur_insert%rowcount;
dbms_output.put_line(i ||' rows inserted from table player to table ODI_player successfully');
close cur_insert;
commit;
end;
/

NITIN KUMAR SINGAUR 112 | P a g e MCA – 1st SEMESTER


Output:-

NITIN KUMAR SINGAUR 113 | P a g e MCA – 1st SEMESTER


32. Write a program in PL/SQL to create an implicit cursor with for loop.
Coding:
begin
dbms_output.put_line('Author : Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('MCA-1st SEMESTER');
dbms_output.put_line('Unit - 4th');
for rec_employee in(select eid,ename,dept,salary from empdev )
loop
dbms_output.put_line(
rec_employee.eid||' '||
rec_employee.ename||' '||
rec_employee.dept||' '||
rec_employee.salary);
end loop;
end;
/

Output:-

NITIN KUMAR SINGAUR 114 | P a g e MCA – 1st SEMESTER


33. Write a program in PL/SQL to create explicit cursor with for loop.
Coding:
declare
cursor cur_staffs
is
select sid,sname,saddress,contacts from staffs;
begin
dbms_output.put_line('Author : Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('MCA-1st SEMESTER');
dbms_output.put_line('Unit - v');
for rec_staffs in cur_staffs
loop
dbms_output.put_line(
rec_staffs.sid||' '||
rec_staffs.sname||' '||
rec_staffs.saddress||' '||
rec_staffs.contacts);
end loop;
end;
/
Output:

NITIN KUMAR SINGAUR 115 | P a g e MCA – 1st SEMESTER


34. Write a program in PL/SQL program to Find Factorial of a Number.
Coding:
declare
num integer;
fact number := 1;
temp integer;
begin
dbms_output.put_line('Path: pro33');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
num := &num;
temp := num;
while temp>0
loop
fact := fact * temp;
temp := temp-1;
end loop;
dbms_output.put_line('factorial of '||num||' is : '||fact);
end;
/
Output:-

NITIN KUMAR SINGAUR 116 | P a g e MCA – 1st SEMESTER


35. Write a program in PL/SQL program to print Table of a Number.
Coding:
declare
a integer := '&number';
i integer;
num integer;
begin
dbms_output.put_line('Path: pro34');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
dbms_output.put_line('table of '||a||' is : ');
num := 0;
for b in 1..10
loop
num := a*b;
dbms_output.put_line(a||' * '||b||' = '||num);
end loop;
end;
/

Output:-

NITIN KUMAR SINGAUR 117 | P a g e MCA – 1st SEMESTER


36. Write a program in PL/SQL program for Reverse of a Number.
Coding:
declare
num integer;
rev integer;
begin
dbms_output.put_line('Path: pro35');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
num := &num;
rev := 0;
while num>0
loop
rev := (rev*10) + mod(num,10);
num := floor(num/10);
end loop;
dbms_output.put_line('reverse of the number is : '||rev);
end;
/
Output:-

NITIN KUMAR SINGAUR 118 | P a g e MCA – 1st SEMESTER


37. Write a program in PL/SQL program to reverse a string.
Coding:
declare
str varchar2(10) := '&string';
len number;
str1 varchar2(10);
i number;
begin
dbms_output.put_line('Path: pro36');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
len := length(str);
for i in reverse 1..len loop
str1 := str1 || Substr(str, i, 1);
end loop;
dbms_output.put_line('reverse of string : '||str1 );
end;
/
Output:-

NITIN KUMAR SINGAUR 119 | P a g e MCA – 1st SEMESTER


38. Write a program in PL/SQL program for Palindrome Number.
Coding:
declare
n integer := '&number';
temp integer;
remainder integer;
sum1 number := 0;
begin
dbms_output.put_line('Path: pro37');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
temp := n;
while n>0
loop
remainder := mod(n , 10);
sum1 := remainder + (sum1*10);
n := trunc(n / 10);
end loop;
if temp=sum1
then
dbms_output.put_line('Entered number is palindrome');
else
dbms_output.put_line('Entered number is not palindrome');
end if;
end;
/

Output:-

NITIN KUMAR SINGAUR 120 | P a g e MCA – 1st SEMESTER


39. Write a program in PL/SQL program to swap two Numbers.
Coding:
declare
num1 number;
num2 number;
temp number;
begin
dbms_output.put_line('Path: pro38');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
num1 := &num1;
num2 := &num2;
temp := num1;
num1 := num2;
num2 := temp;
dbms_output.put_line('After Swapping Values Are : ');
dbms_output.put_line('num1 : '||num1);
dbms_output.put_line('num2 : '||num2);
end;
/

Output:-

NITIN KUMAR SINGAUR 121 | P a g e MCA – 1st SEMESTER


40. Write a program in PL/SQL program for Armstrong Number.
Coding:
declare
n integer;
temp integer;
remainder integer;
sum1 number := 0;
begin
dbms_output.put_line('Path: pro39');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
n := &n;
temp := n;
while n>0
loop
remainder := mod(n , 10);
sum1 := sum1 + power(remainder , 3);
n := trunc(n / 10);
end loop;
if temp=sum1
then
dbms_output.put_line('Entered number is armstrong');
else
dbms_output.put_line('Entered number is not armstrong');
end if;
end;
/

Output:-

NITIN KUMAR SINGAUR 122 | P a g e MCA – 1st SEMESTER


41. Write a program in PL/SQL program to Find area of Circle , Rectangle ,
Parallelogram where user choose the option .
Coding:
declare
choice integer;
radius integer := 6;
height integer := 5;
width integer :=8;
base integer := 6;
height1 integer := 3;
area number(6,2);
begin
dbms_output.put_line('Path: pro40');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
dbms_output.put_line('1.Calulate area of Circle');
dbms_output.put_line('2.Calulate area of Ractangle');
dbms_output.put_line('3.Calulate area of Parallelogram ');
choice := &choice;
case choice
when 1 then
area := 3.14*radius*radius;
dbms_output.put_line('Area of Circle : '||area);
when 2 then
area := height*width;
dbms_output.put_line('Area of Ractangle : '||area);
when 3 then
area := base*height1;
dbms_output.put_line('Area of Parallelogram : '||area);
else
dbms_output.put_line('invalid choice ');
end case;
end;
/

NITIN KUMAR SINGAUR 123 | P a g e MCA – 1st SEMESTER


Output:-

NITIN KUMAR SINGAUR 124 | P a g e MCA – 1st SEMESTER


NITIN KUMAR SINGAUR 125 | P a g e MCA – 1st SEMESTER
42.WAP in PL/SQL to generate pattern:
i)
*
**
***
****
*****
Coding:
declare
n number := 5;
i number;
j number;
begin
dbms_output.put_line('Path: pro41');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
for i in 1..n
loop
for j in 1..i
loop
dbms_output.put('*');
end loop;
dbms_output.new_line();
end loop;
end;
/

Output:

NITIN KUMAR SINGAUR 126 | P a g e MCA – 1st SEMESTER


ii)
*****
****
***
**
*
Coding
declare
n number := 5;
i number;
j number;
begin
dbms_output.put_line('Path: pro42');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
for i in 1..n
loop
for j in i..n
loop
dbms_output.put('*');
end loop;
dbms_output.new_line();
end loop;
end;
/

Output:

NITIN KUMAR SINGAUR 127 | P a g e MCA – 1st SEMESTER


iii)
*
**
***
****
*****
Coding:
declare
n number := 5;
i number;
j number;
k number;
begin
dbms_output.put_line('Path: pro42');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
dbms_output.new_line;
for i in 1..n
loop
for j in 1..n-i
loop
dbms_output.put(' ');
end loop;
for k in 1..i
loop
dbms_output.put('*');
end loop;
dbms_output.new_line;
end loop;
end;
/
Output:

NITIN KUMAR SINGAUR 128 | P a g e MCA – 1st SEMESTER


iv)
*****
****
***
**
*
Coding:
declare
n number := 5;
i number;
j number;
k number;
begin
dbms_output.put_line('Path: pro42');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
dbms_output.new_line;
for i in reverse 1..n
loop
for j in reverse 1..n-i
loop
dbms_output.put(' ');
end loop;
for k in reverse 1..i
loop
dbms_output.put('*');
end loop;
dbms_output.new_line;
end loop;
end;
/
Output:

NITIN KUMAR SINGAUR 129 | P a g e MCA – 1st SEMESTER


v)
*
***
*****
*******
*********
Coding:
declare
n number := 10;
i number :=1;
j number;
k number;
begin
dbms_output.put_line('Path: pro42');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
dbms_output.new_line;
while i<n
loop
j:=1;
while j<n-i
loop
dbms_output.put(' ');
j:=j+2;
end loop;
for k in 1..i
loop
dbms_output.put('*');
end loop;
dbms_output.new_line;
i:=i+2;
end loop;
end;
/
Output:

NITIN KUMAR SINGAUR 130 | P a g e MCA – 1st SEMESTER


vi)
*********
*******
*****
***
*
Coding:
declare
i number:=9;
j number;
k number;
begin
dbms_output.put_line('Path: pro42');
dbms_output.put_line('Author:- Nitin Kumar Singaur');
dbms_output.put_line('Date:- 21/12/2022 ');
dbms_output.put_line('unit:- V ');
dbms_output.put_line('MCA-1st SEMESTER');
dbms_output.new_line;
while i>=1
loop
j:=9;
while j>i
loop
dbms_output.put(' ');
j:=j-2;
end loop;

for k in 1..i
loop
dbms_output.put('*');
end loop;
dbms_output.new_line;
i:=i-2;
end loop;
end;
/
Output:

NITIN KUMAR SINGAUR 131 | P a g e MCA – 1st SEMESTER

You might also like