SQL>
SQL>
SQL> CREATE TABLE gifts (
2 gift_id INTEGER CONSTRAINT gifts_pk PRIMARY KEY,
3 gift_type_id INTEGER ,
4 name VARCHAR2(30) NOT NULL,
5 description VARCHAR2(50),
6 price NUMBER(5, 2)
7 );
Table created.
SQL>
SQL> INSERT INTO gifts (gift_id, gift_type_id, name, description, price) VALUES (1, 1, 'Flower', 'Birthday', 19.95);
1 row created.
SQL> INSERT INTO gifts (gift_id, gift_type_id, name, description, price) VALUES (2, 1, 'Computer', 'New Year', 30.00);
1 row created.
SQL> INSERT INTO gifts (gift_id, gift_type_id, name, description, price) VALUES (3, 2, 'iPod', 'Birthday', 25.99);
1 row created.
SQL> INSERT INTO gifts (gift_id, gift_type_id, name, description, price) VALUES (4, 2, 'iPhone', 'New Year', 13.95);
1 row created.
SQL> INSERT INTO gifts (gift_id, gift_type_id, name, description, price) VALUES (5, 2, 'Book', 'Birthday', 49.99);
1 row created.
SQL>
SQL> CREATE OR REPLACE PROCEDURE updatePrice(p_gift_id IN gifts.gift_id%TYPE,p_factor IN NUMBER) AS
2 v_gift_count INTEGER;
3 BEGIN
4 SELECT COUNT(*) INTO v_gift_count FROM gifts WHERE gift_id = p_gift_id;
5
6 IF v_gift_count = 1 THEN
7 UPDATE gifts SET price = price * p_factor WHERE gift_id = p_gift_id;
8 COMMIT;
9 END IF;
10 EXCEPTION
11 WHEN OTHERS THEN
12 ROLLBACK;
13 END updatePrice;
14 /
Procedure created.
SQL>
SQL>
SQL> drop table gifts;
Table dropped.
|