0% found this document useful (0 votes)
78 views6 pages

It6202 Lab - 002

The document provides the structure and sample data for a PARTS table. It then lists 10 questions asking the user to write SQL queries against the PARTS table to generate various reports by selecting, renaming, calculating on columns. The SELECT statement is used to query the database and generate result sets but does not make any permanent changes to the database.

Uploaded by

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

It6202 Lab - 002

The document provides the structure and sample data for a PARTS table. It then lists 10 questions asking the user to write SQL queries against the PARTS table to generate various reports by selecting, renaming, calculating on columns. The SELECT statement is used to query the database and generate result sets but does not make any permanent changes to the database.

Uploaded by

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

Course Code Type Course Code Here

Database Management System


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

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

1. Create a report displaying all rows and columns.


SQL> CREATE TABLE PARTS
2 (PARTNUM CHAR(4) PRIMARY KEY,
3 DESCRIPTION VARCHAR(20),
4 ONHAND NUMBER(6),
5 CLASS CHAR(5),
6 WAREHOUSE NUMBER(6),
7 PRICE NUMBER(6));
Table created.
SQL> INSERT INTO PARTS VALUES('AT94', 'IRON',50,'HW',3,2495);
1 row created.
SQL> INSERT INTO PARTS VALUES('BVO6','HOME GYM',45,'SG',2,79495);
1 row created.
SQL> INSERT INTO PARTS VALUES('CD52','MICROWAVE OVEN',32,'AP',1,165);
1 row created.
SQL> INSERT INTO PARTS VALUES('DL71','CORDLESS DRILL',21,'HW',3,12995);
1 row created.
SQL> INSERT INTO PARTS VALUES('DR93','GAS RANGE',21,'AP',2,495);
1 row created.
SQL> INSERT INTO PARTS VALUES('DW11','WASHER',12,'AP',3,399);
1 row created.
SQL> INSERT INTO PARTS VALUES('FD21','STAND MIXER',22,'HW',3,159)
1 row created.
SQL> INSERT INTO PARTS VALUES('KL62','DRYER',12,'AP',1,349);
1 row created.
SQL> INSERT INTO PARTS VALUES('KT03','DISHWASHER',8,'AP',3,595);
1 row created.
SQL> INSERT INTO PARTS VALUES('KV29','TREADMILL',9,'SG',2,1390);
1 row created.
PART 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
2. Create a report by eliminating the duplicate rows for column class and warehouse.
SQL> SELECT DISTINCT CLASS,WAREHOUSE FROM PARTS;

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;

PRICE+(PRICE*10/100) DESCRIPTION CLASS


-------------------- -------------------- -----
2744.5 IRON HW
87444.5 HOME GYM SG
181.5 MICROWAVE OVEN AP
14294.5 CORDLESS DRILL HW
544.5 GAS RANGE AP
438.9 WASHER AP
174.9 STAND MIXER HW
383.9 DRYER AP
654.5 DISHWASHER AP
1529 TREADMILL SG

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.

SQL> SELECT DESCRIPTION,(ONHAND-5)+5*WAREHOUSE, WAREHOUSE FROM PARTS;

DESCRIPTION (ONHAND-5)+5*WAREHOUSE WAREHOUSE


-------------------- ---------------------- ----------
IRON 60 3
HOME GYM 50 2
MICROWAVE OVEN 32 1
CORDLESS DRILL 31 3
GAS RANGE 26 2
WASHER 22 3
STAND MIXER 32 3
DRYER 12 1
DISHWASHER 18 3
TREADMILL 14 2

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.

SQL> SELECT PARTNUM||' BELONG TO '||DESCRIPTION AS NUMBER_TITLE FROM PARTS;

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;

NO. OF AVAILABLE WAREHOUSE


--------------------------
1
2
3
10. What is the help of SELECT statement? Is there any permanent made in the database once the user uses
different SELECT.

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.

You might also like