It6202 Lab - 002
It6202 Lab - 002
Direction:
Copy and paste the PARTS table
Copy and paste the PL/SQL code on the space provided after each questions.
Table Name: PARTS
PARTNUM DESCRIPTION ONHAND CLASS WAREHOUSE PRICE
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 NAME DATA TYPE/SIZE KEY NULL
PARTNUM CHAR – 4 PRIMARY NOT NULL
DESCRIPTION VARCHAR – 20 NOT NULL
ONHAND NUMBER – 6
CLASS CHAR – 5
WAREHOUSE NUMBER – 6
PRICE NUMBER – 6
CLASS WAREHOUSE
----- ----------
AP 1
AP 2
SG 2
HW 3
AP 3
3. Create a report specifying only the column PRICE, ONHAND and DESCRIPTION.
SQL> SELECT PRICE,ONHAND,DESCRIPTION FROM PARTS;
PRICE ONHAND DESCRIPTION
---------- ---------- --------------------
2495 50 IRON
79495 45 HOME GYM
165 32 MICROWAVE OVEN
12995 21 CORDLESS DRILL
495 21 GAS RANGE
399 12 WASHER
159 22 STAND MIXER
349 12 DRYER
595 8 DISHWASHER
1390 9 TREADMILL
10 rows selected.
4. Create a report that will add 10% increase in PRICE. List only the column DESCRIPTION, CLASS and
PRICE.
SQL> SELECT PRICE+(PRICE*10/100),DESCRIPTION,CLASS FROM PARTS;
10 rows selected.
5. Create a report that will deduct 5 from ONHAND, multiply 5 in WAREHOUSE, after getting the value
on both ONHAND and WAREHOUSE add their data: as shown below:
ONHAND - 5 + 5 * WAREHOUSE
Note that you have to force the Oracle to prioritize first the Subtraction over Multiplication. List only the
column DESCRIPTION, ONHAND and WAREHOUSE.
10 rows selected.
6. Create a report that will rename the column DESCRIPTION to TITLE, PARTNUM to ID and
ONHAND to STOCK.
SQL> SELECT DESCRIPTION AS TITLE, PARTNUM AS ID, ONHAND AS STOCK FROM
PARTS;
TITLE ID STOCK
-------------------- ---- ----------
IRON AT94 50
HOME GYM BVO6 45
MICROWAVE OVEN CD52 32
CORDLESS DRILL DL71 21
GAS RANGE DR93 21
WASHER DW11 12
STAND MIXER FD21 22
DRYER KL62 12
DISHWASHER KT03 8
TREADMILL KV29 9
10 rows selected.
7. Create a report the will merge the column CLASS and PRICE rename the COLUMN as “CLASS
PRICE”.
SQL> SELECT CLASS||PRICE AS CLASS_PRICE FROM PARTS;
CLASS_PRICE
---------------------------------------------
HW 2495
SG 79495
AP 165
HW 12995
AP 495
AP 399
HW 159
AP 349
AP 595
SG 1390
8. Create a report that will combine the column PARTNUM and DESCRIPTION put a literal character
string “belongs to” in between the two columns then rename the column as “NUMBER TITLE”. Note
put space before and after the character literal string to avoid no spaces in the report.
NUMBER_TITLE
-----------------------------------
AT94 BELONG TO IRON
BVO6 BELONG TO HOME GYM
CD52 BELONG TO MICROWAVE OVEN
DL71 BELONG TO CORDLESS DRILL
DR93 BELONG TO GAS RANGE
DW11 BELONG TO WASHER
FD21 BELONG TO STAND MIXER
KL62 BELONG TO DRYER
KT03 BELONG TO DISHWASHER
KV29 BELONG TO TREADMILL
9. Create a report that will display the unique value for WAREHOUSE rename the column as “No. of
Available Warehouse”.
SELECT DISTINCT WAREHOUSE AS "NO. OF AVAILABLE WAREHOUSE" FROM PARTS;
The help of the select statement is to be able to create a minimal report of what you only want to see in
the database for much more easy way of reviewing a report. There will be no permanent change in the
databases after using different types of select statement.