Lesson 8 | Building a Cursor Block |
Objective | Describe how to Build a Cursor Block |
FOR
loop, an alternate way to write cursor blocks. The following section discusses how to build a cursor block by walking you through the steps.
PETSTORE
as the user name, GREATPETS
as the password, and MYDB
as the host string and clicked the OK button to continue. v_prod_id
of type number and declaring a cursor called get_product
that selects the product ID from product table for the product Rabbit
.
You typed the following text at the following prompts and pressed Enter:
SQL>DECLARE
2>v_prod_id NUMBER;
3>CURSOR get_product IS
SELECT PRODUCT_ID FROM PRODUCT
WHERE PRODUCT_NAME = 'Rabbit';
BEGIN
OPEN get_product;
FETCH get_product INTO v_prod_id;
PET_CARE_LOG
at the following prompt, and pressed Enter:INSERT INTO PET_CARE_LOG
(PRODUCT_ID, LOG_DATETIME, LOG_TEXT)
VALUES (v_prod_id, to_date('2-SEP-99 05:30PM','dd-mon-yy hh:miPM'), 'Rabbits eat fresh grass only.');
CLOSE get_product;
COMMIT;
END;
/