| 1 |
-- available online in file 'examp1' |
| 2 |
DECLARE |
| 3 |
qty_on_hand NUMBER(5); |
| 4 |
BEGIN |
| 5 |
SELECT quantity INTO qty_on_hand FROM inventory |
| 6 |
WHERE product = 'TENNIS RACKET' |
| 7 |
FOR UPDATE OF quantity; |
| 8 |
IF qty_on_hand > 0 THEN -- check quantity |
| 9 |
UPDATE inventory SET quantity = quantity - 1 |
| 10 |
WHERE product = 'TENNIS RACKET'; |
| 11 |
INSERT INTO purchase_record |
| 12 |
VALUES ('Tennis racket purchased', SYSDATE); |
| 13 |
ELSE |
| 14 |
INSERT INTO purchase_record |
| 15 |
VALUES ('Out of tennis rackets', SYSDATE); |
| 16 |
END IF; |
| 17 |
COMMIT; |
| 18 |
END; |
| 19 |
|
| 20 |
-- From https://docs.oracle.com/cd/B10500_01/appdev.920/a96624/01_oview.htm#7106 |
| 21 |
|