You are on page 1of 5

Course Code Type Course Code Here

Database Management System


Description
1
College / Department:
LabExer No. 003
Online Education
Laboratory Exercise Page 1 of 1

Direction:
 Use the Parts table in LabExer003 (previous week)
 Copy and paste the PL/SQL code on the space provided after each questions.
Table Name: PARTS
PARTNU DESCRIPTION ONHAN CLASS WAREHOUS PRICE
M D E
AT94 IRON 50 HW 3 2495
BVO6 HOME GYM 45 SG 2 79495
CD52 MICROWAVE OVEN 32 AP 1 165
DL71 CORDLESS DRILL 21 HW 3 12995
DR93 GAS RANGE 21 AP 2 495
DW11 WASHER 12 AP 3 399
FD21 STAND MIXER 22 HW 3 159
KL62 DRYER 12 AP 1 349
KT03 DISHWASHER 8 AP 3 595
KV29 TREADMILL 9 SG 2 1390

INSERT INTO PARTS2VALUES('AT94', 'IRON',50,'HW',3,2495);


INSERT INTO PARTS2VALUES('BVO6','HOME GYM'     ,45,'SG',2,79495);
INSERT INTO PARTS2VALUES('CD52','MICROWAVE OVEN',32,'AP',1,165);
INSERT INTO PARTS2VALUES('DL71','CORDLESS DRILL',21,'HW',3,12995);
INSERT INTO PARTS2VALUES('DR93','GAS RANGE',21,'AP',2,495);
INSERT INTO PARTS2VALUES('DW11','WASHER',12,'AP',3,399);
INSERT INTO PARTS2VALUES('FD21','STAND MIXER',22,'HW',3,159);
INSERT INTO PARTS2VALUES('KL62','DRYER',12,'AP',1,349);
INSERT INTO PARTS2VALUES('KT03','DISHWASHER',8,'AP',3,595);
INSERT INTO PARTS2VALUES('KV29','TREADMILL',9,'SG',2,1390);
PARTS structure
COLUMN NAME DATA TYPE/SIZE KEY N
PARTNUM CHAR – 4 PRIMARY N
DESCRIPTION VARCHAR – 20 N
ONHAND NUMBER – 6
CLASS CHAR – 5
WAREHOUSE NUMBER – 6
PRICE NUMBER – 6

Tabl Dat Indexe Mode Constraint Grant UI Trigger Dependencie


e a s l s s StatisticsDefaults s s SQL
CREATE TABLE "PARTS2"
( "PARTUM" CHAR(4) NOT NULL ENABLE,
"DESCRIPTION" VARCHAR2(20) NOT NULL ENABLE,
"ONHAND" NUMBER(6,0),
"CLASS" CHAR(5),
"WAREHOUSE" NUMBER(6,0),
"PRICE" NUMBER(6,0),
CONSTRAINT "PARTS2_PK" PRIMARY KEY ("PARTUM") ENABLE
) ;
1. Create a report listing only the column DESCRIPTION, PARTNUM, CLASS, and PRICE of all PART
whose CLASS is equal to HW.
 Select DESCRIPTION, PARTUM, CLASS, PRICE from PARTS2 where CLASS = “HW”;
2. Create a report listing only the column PARTNUM, DESCRIPTION and PRICE of all PARTS where
price is less than 500. Sort the PRICE in ascending order.
 Select PARTUM, DESCRIPTION, PRICE from PARTS2 where PRICE <500;
3. Create a report listing only the column DESCRIPTION, ONHAND and WAREHOUSE of all PARTS
where ONHAND is greater than or equal to 21.
 Select DESCRIPTION, ONHAND, WAREHOUSE from PARTS2 where ONHAND >=21;
4. Create a report listing only the column DESCRIPTION, CLASS and PRICE of all PARTS where class
is not equal to AP.
 Select DESCRIPTION, CLASS, PRICE from PARTS2 WHERE CLASS NOT LIKE ‘%AP’;
5. Create a report listing only the column CLASS, DESCRITPION and PRICE of all PARTS where price
range is between 200 to 500. Sort the Price in descending order.
 Select CLASS, DESCRIPTION, PRICE from PARTS2 where PRICE between 200 and between
500;
6. Create a report listing only the column PARTNUM, CLASS and ONHAND of all parts where partnum
is equal to AT94, DR93 and KV29. (Note 1 query only and do not use logical condition)
 Select PARTUM, CLASS, ONHAND from PARTS2 where PARTUM IN
(‘AT94’,’DR93’,’KV29’);
7. Create a report listing only the column DESCRIPTION, ONHAND, CLASS and PRICE of all price
where the description ends with letter ‘N’.
 Select DESCRIPTION, ONHAND, CLASS, PRICE from PARTS2 where DESCRIPTION
LIKE ‘N%’;
8. Create a report listing only the column DESCRIPTION, WAREHOUSE, CLASS and PRICE of all parts
where the description contains keyword ‘SHE’.
 Select DESCRIPTION, WAREHOUSE, CLASS, PRICE from PARTS2 where DESCRIPTION
LIKE ‘%SHE%’;
9. Create a report listing only the column DESCIPTION, PARTNUM, CLASS and PRICE of all parts
where the description fourth letter starting from the first is equal to ‘D’.
 Select DESCRIPTION, PARTUM, CLASS, PRICES from PARTS2 where DESCRIPTION like
‘D%’;
10. Create a report showing all rows and columns sort the description in ascending order.
 Select *FROM PARTS2 ORDER BY DESCRIPTION ASC;
11. Create a report that will merge the column DESCRIPTION and PRICE put a literal character string of =
“ with a price of ” in between the two columns. Limit the rows returned by getting only the partnum that
starts with letter ‘K’.
 Select (DESCRIPTION|| ‘with a price of’|| PRICE) from PARTS2 where PARTUM LIKE ‘%K’;
12. Create a report that will display the distinct value for CLASS and WAREHOUSE limit the rows by
getting only the parts under WAREHOUSE 3.
 Select CLASS, WAREHOUSE from PARTS2 where WAREHOUSE = ‘3’;
13. Create a report by listing the column DESCRIPTION, WAREHOUSE and ONHAND. Get only the
warehouse value equal to 3 and the onhand value is equal to 21.
 Select DESCRIPTION, WAREHOUSE, ONHAND from PARTS2 where WAREHOUSE =3,
where ONHAND =21;
14. Create a report by listing the column PARTNO, DESCRIPTION and PRICE. Get only those Partnum
that either starts with letter ‘K’ or price that is less than 500. Sort your report by price in ascending
order.
 Select PARTUM, DESCRIPTION, PRICE from PARTS2 where PARTUM like ‘%K’; where
PRICE <500;
15. Create a report by listing the column PARTNO, DESCRIPTION and WAREHOUSE. Get only that
description that does not ends with ‘ER’. Note that you have to merge the said three columns, rename
the merge column as “Parts Record”. Below is the sample output for column.
Parts Record
AT94 is the part number of IRON which belong to warehouse 3
 Select (PARTUM || ‘is the part number of’ ||DESCRIPTION || ‘which belongs to’ ||
WAREHOUSE) from PARTS2 where PARTUM LIKE ‘%ER’;
16. Create a report by listing the DESCRIPTION and Price (Note that in column PRICE add ADDITIONAL
10000). Get only the prices with no digit that is equal to ‘5’. Note that you have to concatenate the said
column and rename the merge column as “New Price Lists”. Sort the data in DESC order by Price.
 Select DESCRIPTION, PRICE + 1000 AS “NEW PRICE LIST” from PARTS2 ORDER BY
PRICE;
17. Write the different select clause following the order of precedence.
 FROM
 WHERE
 GROUP BY
 HAVING
 SELECT
 ORDER BY
 LIMIT
18. What is the default order of sorting data in oracle? Write one example.
 By default, the ORDER BY clause sorts rows in ascending order whether you specify ASC or
not. If you want to sort rows in descending order, you use DESC explicitly.
 Example: Select *FROM PARTS2 ORDER BY DESCRIPTION ASC;
19. When is LIKE condition properly used?
 The LIKE condition is properly used in the WHERE CLAUSE of a SELECT, INSERT,
UPDATE OR DELETE statement. It also allows you to use wildcards to perform pattern
matching in a query.
20. When is IN condition properly used?
 The IN condition is used to test a value for membership in a list of values or subquery.

You might also like