It6202 Lab - 003
It6202 Lab - 003
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
PARTNUM DESCRIPTION ONHAND CLAS WAREHOUSE PRICE
S
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
PARTS structure
COLUMN DATA KEY NULL
NAME TYPE/SIZE
PARTNUM CHAR – 4 PRIMARY NOT NULL
DESCRIPTION VARCHAR – 20 NOT NULL
ONHAND NUMBER – 6
CLASS CHAR – 5
WAREHOUSE NUMBER – 6
PRICE NUMBER – 6
1. Create a report listing only the column DESCRIPTION, PARTNUM, CLASS, and PRICE of all PART
whose CLASS is equal to HW.
- SQL> SELECT DESCRIPTION, PARTNUM, PRICE FROM PARTS 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.
- SQL> SELECT PARTNUM, DESCRIPTION, PRICE FROM PARTS WHERE PRICE < '500' ORDER BY PRICE ASC;
3. Create a report listing only the column DESCRIPTION, ONHAND and WAREHOUSE of all PARTS
where ONHAND is greater than or equal to 21.
- SQL> SELECT DESCRIPTION, ONHAND, WAREHOUSE FROM PARTS 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.
- SQL> SELECT DESCRIPTION, CLASS, PRICE FROM PARTS WHERE CLASS <> '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.
- SQL> SELECT CLASS, DESCRIPTION, PRICE FROM PARTS WHERE PRICE BETWEEN 200 AND 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)
- SQL> SELECT PARTNUM, CLASS, ONHAND FROM PARTS WHERE PARTNUM 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’.
- SQL> SELECT DESCRIPTION, ONHAND, CLASS, PRICE FROM PARTS 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’.
- SQL> SELECT DESCRIPTION, WAREHOUSE, CLASS, PRICE FROM PARTS 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’.
- SQL> SELECT DESCRIPTION, PARTNUM, CLASS, PRICE FROM PARTS WHERE DESCRIPTION LIKE 'D%';
10. Create a report showing all rows and columns sort the description in ascending order.
- SQL> SELECT * FROM PARTS 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’.
- SQL> SELECT (DESCRIPTION|| 'WITH A PRICE OF' || PRICE) FROM PARTS WHERE PARTNUM 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.
- SQL> SELECT DISTINCT CLASS, WAREHOUSE FROM PARTS 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.
- SQL> SELECT DESCRIPTION, WAREHOUSE, ONHAND FROM PARTS WHERE WAREHOUSE = '3' AND 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.
- SQL> SELECT PARTNUM, DESCRIPTION, WAREHOUSE FROM PARTS WHERE PARTNUM LIKE 'K%' OR PRICE <
'500' ORDER BY PRICE ASC;
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
- SQL> SELECT (PARTNUM || 'IS THE PART NUMBER OF' || DESCRIPTION || 'WHICH BELONGS TO' ||
WAREHOUSE) FROM PARTS WHERE PARTNUM NOT 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.
- SQL> SELECT (DESCRIPTION||(PRICE+10000)) AS "NEW PRICE LISTS"
2 from PARTS
3 WHERE PRICE NOT IN ('5')
4 ORDER BY PRICE DESC;
17. Write the different select clause following the order of precedence.
- SELECT column_list FROM table-name
[WHERE Clause]
[GROUP BY clause]
[ORDER BY clause];
18. What is the default order of sorting data in oracle? Write one example.
- SQL Server will guarantee a sort order in your SELECT statement unless you also include an
ORDER BY clause.
Example: SELECT <column> FROM <table> ORDER BY <column>;
19. When is LIKE condition properly used?
- The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
20. When is IN condition properly used?
- The IN operator allows you to easily test if an expression matches any value in a list of values. It is used to
help reduce the need for multiple OR conditions in a SELECT, INSERT, UPDATE, or DELETE statement.