Sunteți pe pagina 1din 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

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
) ;

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.


CREATE TABLE PARTS2(
PARTNUM CHAR(4) PRIMARY KEY,
DESCRIPTION VARCHAR(20),
ONHAND NUMBER(6),
CLASS CHAR(5),
WAREHOUSE NUMBER(6),
PRICE NUMBER(6));
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);
2. C
r
e
a
t
e

a report by eliminating the duplicate rows for column class and warehouse.
 select distinct * from parts2 group by class, warehouse;

3. Create a report specifying only the column PRICE, ONHAND and DESCRIPTION.
 select "PARTS2"."DESCRIPTION" as "DESCRIPTION",
"PARTS2"."ONHAND" as "ONHAND",
"PARTS2"."PRICE" as "PRICE"
from "PARTS2" "PARTS2"
4. Create a report that will add 10% increase in PRICE. List only the column DESCRIPTION, CLASS and
PRICE.
select DESCRIPTION, CLASS, PRICE*1.10 from parts2;

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.
 Select Description, onhand-5 as new_onhand, warehouse*5 as new_warehouse, (onhand-5)+
(warehouse*5) as onhand_warehouse from parts2;

6. Create a report that will rename the column DESCRIPTION to TITLE, PARTNUM to ID and
ONHAND to STOCK.
 alter table "PARTS2" rename column "DESCRIPTION" to "TITLE" /
 alter table "PARTS2" rename column "PARTUM" to "ID" /
 alter table "PARTS2" rename column "ONHAND" to "STOCK" /
7. Create a report the will merge the column CLASS and PRICE rename the COLUMN as “CLASS
PRICE”.
 Select class||price as “class price” from parts2;

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.
 Select id|| ‘belongs to’ || title as “number title from parts2;
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 parts2;

10. What is the help of SELECT statement? Is there any permanent made in the database once the user uses
different SELECT.
 A SELECT statement means retrieves zero or more rows from one or more database tables or
views. It is also helpful in terms of performing queries and access individual fields or entire rows
from the result set. A user can still use other SELECT depending on the need of the user.

S-ar putea să vă placă și