Sem 3 Dbms Practical File 180305021716 PDF
Sem 3 Dbms Practical File 180305021716 PDF
BMS
S LA
AB
NEIL MATHEW
M W - A23
3247100
002 - 3C
CS4 – Y3305
INDEX
EMPNO NUMBER(4),
ENAME VARCHAR2(20),
JOB CHAR(10),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(9,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2)
);
Table created.
12 rows selected.
(i) Creating table DEPT.
DEPTNO NUMBER(2),
DNAME varchar2(20),
LOC varchar2(10)
);
Table created.
UOM VARCHAR2(4),
ROL NUMBER(5),
ROQ NUMBER(5),
);
Table created.
9 rows selected.
(i) Creating table TRANSACTION.
ITNO NUMBER(4),
TYPE VARCHAR2(10),
QTY NUMBER(4),
RECEIPTNO VARCHAR2(20),
DOT DATE
);
Table created.
16 rows selected.
Q1
(i) List the employees belonging to the department number 20.
4 rows in set.
(ii) List the Names and Salaries of the employees whose salary is more than 1000.
ENAME SAL
Allen 1600
Ward 1250
Jones 2975
Martin 1250
Blake 2850
Clark 2450
Scott 3000
King 5000
Turner 1500
Ford 3000
10 rows in set.
(iii) List the Employee number and Name of the Managers.
EMPNO ENAME
7566 Jones
7698 Blake
7782 Clark
3 rows in set.
(iv) List the name of the clerk working in department number 20.
SELECT ENAME FROM EMP WHERE JOB LIKE 'Clerk' AND DEPTNO=20;
ENAME
Smith
1 row in set.
(v) List details of employees who have joined before the end of September ’81.
8 rows in set.
(vi) List the employee names of those who are not eligible for commission.
ENAME
Smith
Jones
Blake
Clark
Scott
King
Adams
Ford
8 rows in set.
(vii) List name of employees who are more than 2 years old in organization.
ENAME
Smith
Allen
Ward
Jones
Martin
Blake
Clark
Scott
King
Turner
Adams
Ford
12 rows selected.
(viii) List the total, maximum, minimum and average salary of employees, jobwise for
department number 20.
3 rows in set.
(ix) List names of all employees who have ‘ll’ and ‘tt’ in their name.
ENAME
Allen
Scott
2 rows in set.
(x) List lowest paid employee working for each manager. Sort the output by salary.
(SELECT MIN(SAL) FROM EMP WHERE MGR IS NOT NULL GROUP BY MGR)
ORDER BY SAL;
7 rows selected.
Q2
(i) List the Job, No of employees in each job. The result should be in descending
order of the number of employees.
JOB COUNT(*)
Salesman 4
Manager 3
Analyst 2
Clerk 2
President 1
5 rows selected.
(ii) List the average salary from each job excluding manager.
JOB AVG(SAL)
Analyst 3000
Clerk 875
President 5000
Salesman 1400
4 rows selected.
Q3
(i) Display item name, number and Qoh of all items where Qoh is more than 100.
9 rows selected.
(ii) List the items which have been issued more than 3 times.
ITNO NAME
1090 Hammer
(iii) List the item number, name and value of the cheapest item.
1 rows selected.
(iv) List item name of an
n item if and
d only if the item was reeceived morre than 5 tim
mes.
SELECTT NAME FR
ROM ITEM_MMASTER WHERE ITNO IN
( SE
ELECT ITNO
O FROM TRRANSACTION YPE LIKE 'receive'
N WHERE TY
GROU
UP BY ITNOO HAVING COUNT(ITNNO) > 5 );
NAME
Dish Washerr
(v) List the value of items rounded to one decimal place.
ROUND(RATE,1)
400.9
800.9
5000.9
950.9
6000.7
750.6
750.1
300.9
250.8
9 rows selected.
SUBSTR(EN
Smi
All
War
Jon
Mar
Bla
Cla
Sco
Kin
Tur
Ada
For
12 rows selected.
(vii) List the different
d uniit of measurrements avaailable in table.
UOM
pcs
p
watt
w
volt
v
3 row
ws selected
d.
SEL
LECT * FRO
OM ITEM_M
MASTER WHE
ERE CLASS LIKE ‘C’ AND RATE
E > 2000;
ITN
NO NAME
N QOH CLA UOOM ROL ROQ RATE
1088
1 Lawn Mover
M 123 C pcs 21 21 5000.88
8
1 ro
ow selected.
.
(ix) List the details of all employees in department 10 and 20 in alphabetical order.
6 rows selected.
UPDATE ITEM_MASTER SET RATE = RATE + 0.12*RATE WHERE CLASS LIKE 'B';
3 rows updated.
9 rows selected.
(xi) List the rate of item which has at least 3 receipts.
RATE
950.87
400.9
(xii) Update the QOH of items to QOH + 100
9 rows selected.
(xiii) Delete deetails of item
ms that havee no transacctions taking place in th
he last two
months.
DELETE FROM ITEM
M_MASTER W
WHERE ITN
NO IN
( SELECT
T DISTINCT
T ITNO FRO
OM ITEM_M
MASTER
MINUS
NTHS_BETWEEN(SYSDA
WHERE MON ATE, DOT)<
<=2 );
5 ro
ows deleted.
.
SE
ELECT * FROM ITEM_
_MASTER;
ITN
NO NAME QOH CLA U
UOM ROL
L ROQ RATE
1090
1 Hamm mer 234 A pcss 12 344 400.9
9
1089
1 Saw 456 B pcss 17 233 800.89
9
1087
1 Dish Washer
W 234 A pcss 76 455 950.87
7
1890
1 Battery
y 189 A voltt 30 400 300.9
9
(xiv) List the items for which one transaction was made.
ITNO NAME
1089 Saw
1609 Alternator
(xv) List the number of items belonging to each class, minimum, maximum, average rates
and total value of items in each class.
3 rows selected.
Table created.
3 rows selected.
Q4
(i) List all employees’ names, jobs and deptno who have the same job as that of any
employee in department No: 20.
WHERE JOB IN
7 rows selected.
(ii) Using Self Join, list all the employees who have joined before their manager.
EMPNO ENAME
7521 Ward
7499 Allen
7782 Clark
7698 Blake
7566 Jones
7369 Smith
6 rows selected.
(iii) List all the employees who earn less than the average salary of all employees.
6 rows selected.
(iv) List all the employee names along with their manager’s name. Also list the names
of those employeea who have no manager. (Outer Join)
WHERE W.MGR=M.EMPNO(+);
EMPLOYEE MANAGER
Ford Jones
Scott Jones
Turner Blake
Martin Blake
Ward Blake
Allen Blake
Adams Scott
Clark King
Blake King
Jones King
Smith Ford
King
12 rows selected.
(v) Display the Department which has no employees.
DEPTNO
40
1 row selected.
(vi) List details of employees who earn the minimum salary for their jobs.
ORDER BY JOB;
7 rows selected.
(vii) List the employee name, salary, department No for those employees who earn a
salary greater than average salary for their department. Show the output in
order of department no.
WHERE SAL > (SELECT AVG(SAL) FROM EMP_NM Y WHERE X.DEPTNO = Y.DEPTNO)
ORDER BY DEPTNO;
6 rows selected.
(viii) List details of employees who earn the highest salary for their job.
6 rows selected.
(ix) List the details of those employees who are among the five highest earners of
this company. (TOP N QUERY)
SELECT *
WHERE ROWNUM<=5;
5 rows selected.
(x) List Item no, Name of items whose rate is greater than the lowest rate of an item
belonging to class B.
WHERE RATE > ANY (SELECT RATE FROM ITEM_MASTER WHERE CLASS='B');
ITNO NAME
1067 Baking Oven
1088 Lawn Mover
1087 Dish Washer
1089 Saw
1063 Spark Plug
1609 Alternator
1090 Hammer
1890 Battery
8 rows selected.
Q5
CEIL(7.3) FLOOR(7.3)
8 7
ROUND(7.326,2) TRUNC(7.326,2)
7.33 7.32
MOD(12,5)
2
(iv) Perform a query using RPAD (String Functions)
RPAD('HELLO',7,'!')
Hello!!
RTRIM(LTRIM('MM
AGNET
TRANSLATE(DNAME,'AIEOU','UOEI')
Accounting Accintong
Research Reseurch
Sales Sules
Operations Operutoins
(vii) Perform a query usin
ng NEXT_DA
AY. (Date Fu
unctions)
SELE
ECT NEXT_D
DAY('25-OCT-2011',
, 'WED') F
FROM DUAL
L;
NEXT_
_DAY('25-OCT
T-2
26-OCT
T-11
SELECT TO
O_CHAR( TO
O_DATE('25-OCT-201
11') , 'Da
ay') FROM
M DUAL;
TO_CHAR(TO
T O_DATE('25--OCT-201
Tuesda
ay
(ix) Perform a query using NVL. (General Functions)
SELECT EMPNO, SAL, COMM, SAL + COMM, SAL + NVL(COMM, 0) FROM EMP_NM;
12 rows selected.
NAME DECODE(NAME,'HAMMER','MALLET','SA
Hammer Mallet
Saw Axe
Lawn Mover Unavailable
Dish Washer Unavailable
Baking Oven Unavailable
Spark Plug Unavailable
Alternator Unavailable
Battery Generator
Piston Unavailable
9 rows selected.