0% found this document useful (0 votes)
20 views

q3 4

The document details the creation of database tables and insertion of records into those tables for a company called Clearwater Traders. Tables are created for customers, orders, inventory, etc. and sample records are inserted into each table.

Uploaded by

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

q3 4

The document details the creation of database tables and insertion of records into those tables for a company called Clearwater Traders. Tables are created for customers, orders, inventory, etc. and sample records are inserted into each table.

Uploaded by

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

SQL>

SQL> DROP USER c##gunjan CASCADE;

User dropped.

SQL>
SQL> CREATE USER c##gunjan IDENTIFIED BY gunjan;

User created.

SQL> GRANT connect , resource TO c##gunjan;

Grant succeeded.

SQL> ALTER USER c##gunjan QUOTA 100M on USERs;

User altered.

SQL> connect c##gunjan/gunjan;


Connected.
SQL> SELECT TO_CHAR(sysdate,'DD MM YYY Day HH:MI:SS Am' ) FROM dual;

TO_CHAR(SYSDATE,'DDMMYYYDAYHH:MI:SSAM')
----------------------------------------------------------
10 03 024 Sunday 02:51:59 Pm

SQL>
SQL> --script to create Clearwater Traders database
SQL> -- revised 01/11/2023 Huu Con Nguyen
SQL>
SQL> DROP TABLE order_line CASCADE CONSTRAINTS;
DROP TABLE order_line CASCADE CONSTRAINTS
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> DROP TABLE shipment_line CASCADE CONSTRAINTS;


DROP TABLE shipment_line CASCADE CONSTRAINTS
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> DROP TABLE shipment CASCADE CONSTRAINTS;


DROP TABLE shipment CASCADE CONSTRAINTS
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> DROP TABLE inventory CASCADE CONSTRAINTS;


DROP TABLE inventory CASCADE CONSTRAINTS
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> DROP TABLE color CASCADE CONSTRAINTS;


DROP TABLE color CASCADE CONSTRAINTS
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> DROP TABLE item CASCADE CONSTRAINTS;


DROP TABLE item CASCADE CONSTRAINTS
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> DROP TABLE category CASCADE CONSTRAINTS;


DROP TABLE category CASCADE CONSTRAINTS
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> DROP TABLE orders CASCADE CONSTRAINTS;


DROP TABLE orders CASCADE CONSTRAINTS
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> DROP TABLE order_source CASCADE CONSTRAINTS;


DROP TABLE order_source CASCADE CONSTRAINTS
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> DROP TABLE customer CASCADE CONSTRAINTS;


DROP TABLE customer CASCADE CONSTRAINTS
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL>
SQL> CREATE TABLE customer
2 (c_id NUMBER(5),
3 c_last VARCHAR2(30),
4 c_first VARCHAR2(30),
5 c_mi CHAR(1),
6 c_birthdate DATE,
7 c_address VARCHAR2(30),
8 c_city VARCHAR2(30),
9 c_state CHAR(2),
10 c_zip VARCHAR2(10),
11 c_dphone VARCHAR2(10),
12 c_ephone VARCHAR2(10),
13 c_userid VARCHAR2(50),
14 c_password VARCHAR2(15),
15 CONSTRAINT customer_c_id_pk PRIMARY KEY (c_id));

Table created.
SQL>
SQL> CREATE TABLE order_source
2 (os_id NUMBER(3),
3 os_desc VARCHAR2(30),
4 CONSTRAINT order_source_os_id_pk PRIMARY KEY(os_id));

Table created.

SQL>
SQL> CREATE TABLE orders
2 (o_id NUMBER(8),
3 o_date DATE,
4 o_methpmt VARCHAR2(10),
5 c_id NUMBER(5),
6 os_id NUMBER(3),
7 CONSTRAINT orders_o_id_pk PRIMARY KEY (o_id),
8 CONSTRAINT orders_c_id_fk FOREIGN KEY (c_id) REFERENCES customer(c_id),
9 CONSTRAINT orders_os_id_fk FOREIGN KEY (os_id) REFERENCES
order_source(os_id));

Table created.

SQL>
SQL> CREATE TABLE category
2 (cat_id NUMBER(2),
3 cat_desc VARCHAR2(20),
4 CONSTRAINT category_cat_id_pk PRIMARY KEY (cat_id));

Table created.

SQL>
SQL> CREATE TABLE item
2 (item_id NUMBER(8),
3 item_desc VARCHAR2(30),
4 cat_id NUMBER(2),
5 item_image BLOB,
6 CONSTRAINT item_item_id_pk PRIMARY KEY (item_id),
7 CONSTRAINT item_cat_id_fk FOREIGN KEY (cat_id) REFERENCES category(cat_id));

Table created.

SQL>
SQL> CREATE TABLE color
2 (color VARCHAR2(20),
3 CONSTRAINT color_color_pk PRIMARY KEY (color));

Table created.

SQL>
SQL> CREATE TABLE inventory
2 (inv_id NUMBER(10),
3 item_id NUMBER(8),
4 color VARCHAR2(20),
5 inv_size VARCHAR2(10),
6 inv_price NUMBER(6,2),
7 inv_qoh NUMBER(4),
8 CONSTRAINT inventory_inv_id_pk PRIMARY KEY (inv_id),
9 CONSTRAINT inventory_item_id_fk FOREIGN KEY (item_id) REFERENCES
item(item_id),
10 CONSTRAINT inventory_color_fk FOREIGN KEY (color) REFERENCES color(color));

Table created.

SQL>
SQL> CREATE TABLE shipment
2 (ship_id NUMBER(10),
3 ship_date_expected DATE,
4 CONSTRAINT shipment_ship_id_pk PRIMARY KEY (ship_id));

Table created.

SQL>
SQL> CREATE TABLE shipment_line
2 (ship_id NUMBER(10),
3 inv_id NUMBER(10),
4 sl_quantity NUMBER(4),
5 sl_date_received DATE,
6 CONSTRAINT shipment_line_ship_id_fk FOREIGN KEY (ship_id) REFERENCES
shipment(ship_id),
7 CONSTRAINT shipment_line_inv_id_fk FOREIGN KEY (inv_id) REFERENCES
inventory(inv_id),
8 CONSTRAINT shipment_line_shipid_invid_pk PRIMARY KEY(ship_id, inv_id));

Table created.

SQL>
SQL> CREATE TABLE order_line
2 (o_id NUMBER(8),
3 inv_id NUMBER(10),
4 ol_quantity NUMBER(4) NOT NULL,
5 CONSTRAINT order_line_o_id_fk FOREIGN KEY (o_id) REFERENCES orders(o_id),
6 CONSTRAINT order_line_inv_id_fk FOREIGN KEY (inv_id) REFERENCES
inventory(inv_id),
7 CONSTRAINT order_line_oid_invid_pk PRIMARY KEY (o_id, inv_id));

Table created.

SQL>
SQL>
SQL> --- inserting records into CUSTOMER
SQL> INSERT INTO CUSTOMER VALUES
2 (1, 'Harris', 'Paula', 'E', to_date('04/09/1953', 'mm/dd/yyyy'), '1156 Water
Street, Apt. #3', 'Osseo', 'WI',
3 '54705', '7155558943', '7155559035', 'harrispe', 'asdfjk');

1 row created.

SQL>
SQL> INSERT INTO CUSTOMER VALUES
2 (2, 'Garcia', 'Maria', 'H', to_date('07/14/1958', 'mm/dd/yyyy'), '2211 Pine
Drive', 'Radisson', 'WI',
3 '54867', '7155558332', '7155558332', 'garciamm', '12345');

1 row created.

SQL>
SQL> INSERT INTO CUSTOMER VALUES
2 (3, 'Miller', 'Lee', NULL, to_date('01/05/1936', 'mm/dd/yyyy'), '699 Pluto St.
NW', 'Silver Lake', 'WI',
3 '53821', '7155554978', '7155559002', 'millerl', 'zxcvb');

1 row created.

SQL>
SQL> INSERT INTO CUSTOMER VALUES
2 (4, 'Chang', 'Alissa', 'R', to_date('10/01/1976', 'mm/dd/yyyy'), '987 Durham
Rd.', 'Apple Valley', 'MN',
3 '55712', '7155557651', '7155550087', 'changar', 'qwerui');

1 row created.

SQL>
SQL> INSERT INTO CUSTOMER VALUES
2 (5, 'Edwards', 'Mitch', 'M', to_date('11/20/1986', 'mm/dd/yyyy'), '4204 Garner
Street', 'Washburn', 'WI',
3 '54891', '7155558243', '7155556975', 'edwardsmm', 'qwerty');

1 row created.

SQL>
SQL> INSERT INTO CUSTOMER VALUES
2 (6, 'Nelson', 'Kyle', 'E', to_date('12/04/1984', 'mm/dd/yyyy'), '232 Echo
Rd.', 'Minnetonka', 'MN',
3 '55438', '7151113333', '7155552222', 'nelsonke', 'clever');

1 row created.

SQL>
SQL> --- inserting records into ORDER_SOURCE
SQL> INSERT INTO order_source VALUES (1, 'Winter 2005');

1 row created.

SQL> INSERT INTO order_source VALUES (2, 'Spring 2006');

1 row created.

SQL> INSERT INTO order_source VALUES (3, 'Summer 2006');

1 row created.

SQL> INSERT INTO order_source VALUES (4, 'Outdoor 2006');

1 row created.

SQL> INSERT INTO order_source VALUES (5, 'Children''s 2006');

1 row created.

SQL> INSERT INTO order_source VALUES (6, 'Web Site');

1 row created.

SQL>
SQL> --- inserting records into orders
SQL> INSERT INTO orders VALUES
2 (1, TO_DATE('05/29/2006', 'MM/DD/YYYY'), 'CC', 1, 2);

1 row created.

SQL>
SQL> INSERT INTO orders VALUES
2 (2, TO_DATE('05/29/2006', 'MM/DD/YYYY'), 'CC', 5, 6);

1 row created.

SQL>
SQL> INSERT INTO orders VALUES
2 (3, TO_DATE('05/31/2006', 'MM/DD/YYYY'), 'CHECK', 2, 2);

1 row created.

SQL>
SQL> INSERT INTO orders VALUES
2 (4, TO_DATE('05/31/2006', 'MM/DD/YYYY'), 'CC', 3, 3);

1 row created.

SQL>
SQL> INSERT INTO orders VALUES
2 (5, TO_DATE('06/01/2006', 'MM/DD/YYYY'), 'CC', 4, 6);

1 row created.

SQL>
SQL> INSERT INTO orders VALUES
2 (6, TO_DATE('06/01/2006', 'MM/DD/YYYY'), 'CC', 4, 3);

1 row created.

SQL>
SQL> --- inserting records into CATEGORY
SQL> INSERT INTO category VALUES (1, 'Women''s Clothing');

1 row created.

SQL> INSERT INTO category VALUES (2, 'Children''s Clothing');

1 row created.

SQL> INSERT INTO category VALUES (3, 'Men''s Clothing');

1 row created.

SQL> INSERT INTO category VALUES (4, 'Outdoor Gear');

1 row created.

SQL>
SQL> --- inserting records into ITEM
SQL> INSERT INTO item VALUES
2 (1, 'Men''s Expedition Parka', 3, EMPTY_BLOB());

1 row created.
SQL>
SQL> INSERT INTO item VALUES
2 (2, '3-Season Tent', 4, EMPTY_BLOB());

1 row created.

SQL>
SQL> INSERT INTO item VALUES
2 (3, 'Women''s Hiking Shorts', 1, EMPTY_BLOB());

1 row created.

SQL>
SQL> INSERT INTO item VALUES
2 (4, 'Women''s Fleece Pullover', 1, EMPTY_BLOB());

1 row created.

SQL>
SQL> INSERT INTO item VALUES
2 (5, 'Children''s Beachcomber Sandals', 2, EMPTY_BLOB());

1 row created.

SQL>
SQL> INSERT INTO item VALUES
2 (6, 'Boy''s Surf Shorts', 2, EMPTY_BLOB());

1 row created.

SQL>
SQL> INSERT INTO item VALUES
2 (7, 'Girl''s Soccer Tee', 2, EMPTY_BLOB());

1 row created.

SQL>
SQL> --- inserting records into COLOR
SQL> INSERT INTO color VALUES ('Sky Blue');

1 row created.

SQL> INSERT INTO color VALUES ('Light Grey');

1 row created.

SQL> INSERT INTO color VALUES ('Khaki');

1 row created.

SQL> INSERT INTO color VALUES ('Navy');

1 row created.

SQL> INSERT INTO color VALUES ('Royal');

1 row created.

SQL> INSERT INTO color VALUES ('Eggplant');


1 row created.

SQL> INSERT INTO color VALUES ('Blue');

1 row created.

SQL> INSERT INTO color VALUES ('Red');

1 row created.

SQL> INSERT INTO color VALUES ('Spruce');

1 row created.

SQL> INSERT INTO color VALUES ('Turquoise');

1 row created.

SQL> INSERT INTO color VALUES ('Bright Pink');

1 row created.

SQL> INSERT INTO color VALUES ('White');

1 row created.

SQL>
SQL> --- inserting records into INVENTORY
SQL> INSERT INTO inventory VALUES
2 (1, 2, 'Sky Blue', NULL, 259.99, 16);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (2, 2, 'Light Grey', NULL, 259.99, 12);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (3, 3, 'Khaki', 'S', 29.95, 150);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (4, 3, 'Khaki', 'M', 29.95, 147);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (5, 3, 'Khaki', 'L', 29.95, 0);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (6, 3, 'Navy', 'S', 29.95, 139);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (7, 3, 'Navy', 'M', 29.95, 137);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (8, 3, 'Navy', 'L', 29.95, 115);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (9, 4, 'Eggplant', 'S', 59.95, 135);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (10, 4, 'Eggplant', 'M', 59.95, 168);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (11, 4, 'Eggplant', 'L', 59.95, 187);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (12, 4, 'Royal', 'S', 59.95, 0);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (13, 4, 'Royal', 'M', 59.95, 124);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (14, 4, 'Royal', 'L', 59.95, 112);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (15, 5, 'Turquoise', '10', 15.99, 121);

1 row created.
SQL>
SQL> INSERT INTO inventory VALUES
2 (16, 5, 'Turquoise', '11', 15.99, 111);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (17, 5, 'Turquoise', '12', 15.99, 113);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (18, 5, 'Turquoise', '1', 15.99, 121);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (19, 5, 'Bright Pink', '10', 15.99, 148);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (20, 5, 'Bright Pink', '11', 15.99, 137);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (21, 5, 'Bright Pink', '12', 15.99, 134);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (22, 5, 'Bright Pink', '1', 15.99, 123);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (23, 1, 'Spruce', 'S', 199.95, 114);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (24, 1, 'Spruce', 'M',199.95, 17);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (25, 1, 'Spruce', 'L', 209.95, 0);

1 row created.
SQL>
SQL> INSERT INTO inventory VALUES
2 (26, 1, 'Spruce', 'XL', 209.95, 12);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (27, 6, 'Blue', 'S', 15.95, 50);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (28, 6, 'Blue', 'M', 15.95, 100);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (29, 6, 'Blue', 'L', 15.95, 100);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (30, 7, 'White', 'S', 19.99, 100);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (31, 7, 'White', 'M', 19.99, 100);

1 row created.

SQL>
SQL> INSERT INTO inventory VALUES
2 (32, 7, 'White', 'L', 19.99, 100);

1 row created.

SQL>
SQL> --inserting records into SHIPMENT
SQL>
SQL> INSERT INTO shipment VALUES
2 (1, TO_DATE('09/15/2006', 'MM/DD/YYYY'));

1 row created.

SQL>
SQL> INSERT INTO shipment VALUES
2 (2, TO_DATE('11/15/2006', 'MM/DD/YYYY'));

1 row created.

SQL>
SQL> INSERT INTO shipment VALUES
2 (3, TO_DATE('06/25/2006', 'MM/DD/YYYY'));

1 row created.

SQL>
SQL> INSERT INTO shipment VALUES
2 (4, TO_DATE('06/25/2006', 'MM/DD/YYYY'));

1 row created.

SQL>
SQL> INSERT INTO shipment VALUES
2 (5, TO_DATE('08/15/2006', 'MM/DD/YYYY'));

1 row created.

SQL>
SQL> --inserting records into SHIPMENT_LINE
SQL> INSERT INTO shipment_line VALUES
2 (1, 1, 25, TO_DATE('09/10/2006', 'MM/DD/YYYY'));

1 row created.

SQL>
SQL> INSERT INTO shipment_line VALUES
2 (1, 2, 25, TO_DATE('09/10/2006', 'MM/DD/YYYY'));

1 row created.

SQL>
SQL> INSERT INTO shipment_line VALUES
2 (2, 2, 25, NULL);

1 row created.

SQL>
SQL> INSERT INTO shipment_line VALUES
2 (3, 5, 200, NULL);

1 row created.

SQL>
SQL> INSERT INTO shipment_line VALUES
2 (3, 6, 200, NULL);

1 row created.

SQL>
SQL> INSERT INTO shipment_line VALUES
2 (3, 7, 200, NULL);

1 row created.

SQL>
SQL> INSERT INTO shipment_line VALUES
2 (4, 12, 100, TO_DATE('08/15/2006', 'MM/DD/YYYY'));

1 row created.
SQL>
SQL> INSERT INTO shipment_line VALUES
2 (4, 13, 100, TO_DATE('08/25/2006', 'MM/DD/YYYY'));

1 row created.

SQL>
SQL> INSERT INTO shipment_line VALUES
2 (5, 23, 50, TO_DATE('08/15/2006', 'MM/DD/YYYY'));

1 row created.

SQL>
SQL> INSERT INTO shipment_line VALUES
2 (5, 24, 100, TO_DATE('08/15/2006', 'MM/DD/YYYY'));

1 row created.

SQL>
SQL> INSERT INTO shipment_line VALUES
2 (5, 25, 100, TO_DATE('08/15/2006', 'MM/DD/YYYY'));

1 row created.

SQL>
SQL> --- inserting records into ORDER_LINE
SQL> INSERT INTO order_line VALUES (1, 1, 1);

1 row created.

SQL> INSERT INTO order_line VALUES (1, 14, 2);

1 row created.

SQL> INSERT INTO order_line VALUES (2, 19, 1);

1 row created.

SQL> INSERT INTO order_line VALUES (3, 24, 1);

1 row created.

SQL> INSERT INTO order_line VALUES (3, 26, 1);

1 row created.

SQL> INSERT INTO order_line VALUES (4, 12, 2);

1 row created.

SQL> INSERT INTO order_line VALUES (5, 8, 1);

1 row created.

SQL> INSERT INTO order_line VALUES (5, 13, 1);

1 row created.

SQL> INSERT INTO order_line VALUES (6, 2, 1);


1 row created.

SQL> INSERT INTO order_line VALUES (6, 7, 3);

1 row created.

SQL>
SQL> COMMIT;

Commit complete.

SQL> CREATE OR REPLACE PROCEDURE display_items_with_inventory AS


2 BEGIN
3 FOR item_rec IN (SELECT i.item_id, i.item_desc, i.cat_id
4 FROM item i)
5 LOOP
6 DBMS_OUTPUT.PUT_LINE('Item ID: ' || item_rec.item_id || ', Item
Description: ' || item_rec.item_desc || ', Category ID: ' || item_rec.cat_id);
7
8 FOR inv_rec IN (SELECT inv_id, color, inv_size, inv_price, inv_qoh
9 FROM inventory
10 WHERE item_id = item_rec.item_id)
11 LOOP
12 DBMS_OUTPUT.PUT_LINE('Inventory ID: ' || inv_rec.inv_id || ',
Color: ' || inv_rec.color || ', Size: ' || inv_rec.inv_size || ', Price: ' ||
inv_rec.inv_price || ', Quantity on Hand: ' || inv_rec.inv_qoh);
13 END LOOP;
14
15 DBMS_OUTPUT.PUT_LINE('----------------------------------------');
16 END LOOP;
17 END;
18 /

Procedure created.

SQL> SET SERVEROUTPUT ON;


SQL> exec display_items_with_inventory;
Item ID: 1, Item Description: Men's Expedition Parka, Category ID: 3
Inventory ID: 23, Color: Spruce, Size: S, Price: 199.95, Quantity on Hand: 114
Inventory ID: 24, Color: Spruce, Size: M, Price: 199.95, Quantity on Hand: 17
Inventory ID: 25, Color: Spruce, Size: L, Price: 209.95, Quantity on Hand: 0
Inventory ID: 26, Color: Spruce, Size: XL, Price: 209.95, Quantity on Hand: 12
----------------------------------------
Item ID: 2, Item Description: 3-Season Tent, Category ID: 4
Inventory ID: 1, Color: Sky Blue, Size: , Price: 259.99, Quantity on Hand: 16
Inventory ID: 2, Color: Light Grey, Size: , Price: 259.99, Quantity on Hand: 12
----------------------------------------
Item ID: 3, Item Description: Women's Hiking Shorts, Category ID: 1
Inventory ID: 3, Color: Khaki, Size: S, Price: 29.95, Quantity on Hand: 150
Inventory ID: 4, Color: Khaki, Size: M, Price: 29.95, Quantity on Hand: 147
Inventory ID: 5, Color: Khaki, Size: L, Price: 29.95, Quantity on Hand: 0
Inventory ID: 6, Color: Navy, Size: S, Price: 29.95, Quantity on Hand: 139
Inventory ID: 7, Color: Navy, Size: M, Price: 29.95, Quantity on Hand: 137
Inventory ID: 8, Color: Navy, Size: L, Price: 29.95, Quantity on Hand: 115
----------------------------------------
Item ID: 4, Item Description: Women's Fleece Pullover, Category ID: 1
Inventory ID: 9, Color: Eggplant, Size: S, Price: 59.95, Quantity on Hand: 135
Inventory ID: 10, Color: Eggplant, Size: M, Price: 59.95, Quantity on Hand: 168
Inventory ID: 11, Color: Eggplant, Size: L, Price: 59.95, Quantity on Hand: 187
Inventory ID: 12, Color: Royal, Size: S, Price: 59.95, Quantity on Hand: 0
Inventory ID: 13, Color: Royal, Size: M, Price: 59.95, Quantity on Hand: 124
Inventory ID: 14, Color: Royal, Size: L, Price: 59.95, Quantity on Hand: 112
----------------------------------------
Item ID: 5, Item Description: Children's Beachcomber Sandals, Category ID: 2
Inventory ID: 15, Color: Turquoise, Size: 10, Price: 15.99, Quantity on Hand:
121
Inventory ID: 16, Color: Turquoise, Size: 11, Price: 15.99, Quantity on Hand:
111
Inventory ID: 17, Color: Turquoise, Size: 12, Price: 15.99, Quantity on Hand:
113
Inventory ID: 18, Color: Turquoise, Size: 1, Price: 15.99, Quantity on Hand: 121
Inventory ID: 19, Color: Bright Pink, Size: 10, Price: 15.99, Quantity on Hand:
148
Inventory ID: 20, Color: Bright Pink, Size: 11, Price: 15.99, Quantity on Hand:
137
Inventory ID: 21, Color: Bright Pink, Size: 12, Price: 15.99, Quantity on Hand:
134
Inventory ID: 22, Color: Bright Pink, Size: 1, Price: 15.99, Quantity on Hand:
123
----------------------------------------
Item ID: 6, Item Description: Boy's Surf Shorts, Category ID: 2
Inventory ID: 27, Color: Blue, Size: S, Price: 15.95, Quantity on Hand: 50
Inventory ID: 28, Color: Blue, Size: M, Price: 15.95, Quantity on Hand: 100
Inventory ID: 29, Color: Blue, Size: L, Price: 15.95, Quantity on Hand: 100
----------------------------------------
Item ID: 7, Item Description: Girl's Soccer Tee, Category ID: 2
Inventory ID: 30, Color: White, Size: S, Price: 19.99, Quantity on Hand: 100
Inventory ID: 31, Color: White, Size: M, Price: 19.99, Quantity on Hand: 100
Inventory ID: 32, Color: White, Size: L, Price: 19.99, Quantity on Hand: 100
----------------------------------------

PL/SQL procedure successfully completed.

SQL> CREATE OR REPLACE PROCEDURE display_items_with_inventory_value AS


2 BEGIN
3 FOR item_rec IN (SELECT i.item_id, i.item_desc, i.cat_id
4 FROM item i)
5 LOOP
6 DBMS_OUTPUT.PUT_LINE('Item ID: ' || item_rec.item_id || ', Item
Description: ' || item_rec.item_desc || ', Category ID: ' || item_rec.cat_id);
7
8 FOR inv_rec IN (SELECT inv_id, color, inv_size, inv_price, inv_qoh,
inv_price * inv_qoh AS item_value
9 FROM inventory
10 WHERE item_id = item_rec.item_id)
11 LOOP
12 DBMS_OUTPUT.PUT_LINE('Inventory ID: ' || inv_rec.inv_id || ',
Color: ' || inv_rec.color || ', Size: ' || inv_rec.inv_size || ', Price: ' ||
inv_rec.inv_price || ', Quantity on Hand: ' || inv_rec.inv_qoh || ', Item Value: '
|| inv_rec.item_value);
13 END LOOP;
14
15 DBMS_OUTPUT.PUT_LINE('----------------------------------------');
16 END LOOP;
17 END;
18 /
Procedure created.

SQL> display_items_with_inventory_value;
SP2-0734: unknown command beginning "display_it..." - rest of line ignored.
SQL> exec display_items_with_inventory_value;
Item ID: 1, Item Description: Men's Expedition Parka, Category ID: 3
Inventory ID: 23, Color: Spruce, Size: S, Price: 199.95, Quantity on Hand: 114,
Item Value: 22794.3
Inventory ID: 24, Color: Spruce, Size: M, Price: 199.95, Quantity on Hand: 17,
Item Value: 3399.15
Inventory ID: 25, Color: Spruce, Size: L, Price: 209.95, Quantity on Hand: 0,
Item Value: 0
Inventory ID: 26, Color: Spruce, Size: XL, Price: 209.95, Quantity on Hand: 12,
Item Value: 2519.4
----------------------------------------
Item ID: 2, Item Description: 3-Season Tent, Category ID: 4
Inventory ID: 1, Color: Sky Blue, Size: , Price: 259.99, Quantity on Hand: 16,
Item Value: 4159.84
Inventory ID: 2, Color: Light Grey, Size: , Price: 259.99, Quantity on Hand: 12,
Item Value: 3119.88
----------------------------------------
Item ID: 3, Item Description: Women's Hiking Shorts, Category ID: 1
Inventory ID: 3, Color: Khaki, Size: S, Price: 29.95, Quantity on Hand: 150,
Item Value: 4492.5
Inventory ID: 4, Color: Khaki, Size: M, Price: 29.95, Quantity on Hand: 147,
Item Value: 4402.65
Inventory ID: 5, Color: Khaki, Size: L, Price: 29.95, Quantity on Hand: 0, Item
Value: 0
Inventory ID: 6, Color: Navy, Size: S, Price: 29.95, Quantity on Hand: 139, Item
Value: 4163.05
Inventory ID: 7, Color: Navy, Size: M, Price: 29.95, Quantity on Hand: 137, Item
Value: 4103.15
Inventory ID: 8, Color: Navy, Size: L, Price: 29.95, Quantity on Hand: 115, Item
Value: 3444.25
----------------------------------------
Item ID: 4, Item Description: Women's Fleece Pullover, Category ID: 1
Inventory ID: 9, Color: Eggplant, Size: S, Price: 59.95, Quantity on Hand: 135,
Item Value: 8093.25
Inventory ID: 10, Color: Eggplant, Size: M, Price: 59.95, Quantity on Hand: 168,
Item Value: 10071.6
Inventory ID: 11, Color: Eggplant, Size: L, Price: 59.95, Quantity on Hand: 187,
Item Value: 11210.65
Inventory ID: 12, Color: Royal, Size: S, Price: 59.95, Quantity on Hand: 0, Item
Value: 0
Inventory ID: 13, Color: Royal, Size: M, Price: 59.95, Quantity on Hand: 124,
Item Value: 7433.8
Inventory ID: 14, Color: Royal, Size: L, Price: 59.95, Quantity on Hand: 112,
Item Value: 6714.4
----------------------------------------
Item ID: 5, Item Description: Children's Beachcomber Sandals, Category ID: 2
Inventory ID: 15, Color: Turquoise, Size: 10, Price: 15.99, Quantity on Hand:
121, Item Value: 1934.79
Inventory ID: 16, Color: Turquoise, Size: 11, Price: 15.99, Quantity on Hand:
111, Item Value: 1774.89
Inventory ID: 17, Color: Turquoise, Size: 12, Price: 15.99, Quantity on Hand:
113, Item Value: 1806.87
Inventory ID: 18, Color: Turquoise, Size: 1, Price: 15.99, Quantity on Hand:
121, Item Value: 1934.79
Inventory ID: 19, Color: Bright Pink, Size: 10, Price: 15.99, Quantity on Hand:
148, Item Value: 2366.52
Inventory ID: 20, Color: Bright Pink, Size: 11, Price: 15.99, Quantity on Hand:
137, Item Value: 2190.63
Inventory ID: 21, Color: Bright Pink, Size: 12, Price: 15.99, Quantity on Hand:
134, Item Value: 2142.66
Inventory ID: 22, Color: Bright Pink, Size: 1, Price: 15.99, Quantity on Hand:
123, Item Value: 1966.77
----------------------------------------
Item ID: 6, Item Description: Boy's Surf Shorts, Category ID: 2
Inventory ID: 27, Color: Blue, Size: S, Price: 15.95, Quantity on Hand: 50, Item
Value: 797.5
Inventory ID: 28, Color: Blue, Size: M, Price: 15.95, Quantity on Hand: 100,
Item Value: 1595
Inventory ID: 29, Color: Blue, Size: L, Price: 15.95, Quantity on Hand: 100,
Item Value: 1595
----------------------------------------
Item ID: 7, Item Description: Girl's Soccer Tee, Category ID: 2
Inventory ID: 30, Color: White, Size: S, Price: 19.99, Quantity on Hand: 100,
Item Value: 1999
Inventory ID: 31, Color: White, Size: M, Price: 19.99, Quantity on Hand: 100,
Item Value: 1999
Inventory ID: 32, Color: White, Size: L, Price: 19.99, Quantity on Hand: 100,
Item Value: 1999
----------------------------------------

PL/SQL procedure successfully completed.

SQL> spool off

You might also like