Created
March 7, 2017 03:42
-
-
Save andrelashley/b461b909030c8ca974a2cfdafd9cd6cd to your computer and use it in GitHub Desktop.
An example using cursors in oracle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE | |
-- step1: declare the variables | |
v_product_id product.product_id%type; | |
v_product_name product.product_name%type; | |
v_product_list_price product.list_price%type; | |
-- step 2: declare the cursor | |
CURSOR v_product_cursor IS | |
SELECT product_id, product_name, list_price | |
FROM product | |
ORDER BY product_id; | |
BEGIN | |
-- step 3: open the cursor | |
OPEN v_product_cursor; | |
LOOP | |
-- step 4: fetch the rows from the cursor | |
FETCH v_product_cursor | |
INTO v_product_id, v_product_name, v_product_list_price; | |
EXIT WHEN v_product_cursor%NOTFOUND; | |
SYS.DBMS_OUTPUT.PUT_LINE('v_product_id = ' || v_product_id || | |
', v_product_name = ' || v_product_name || ', v_list_price = ' | |
|| v_product_list_price); | |
END LOOP; | |
-- step 5: close the cursor | |
CLOSE v_product_cursor; | |
END; | |
/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment