The following tutorial requires the knowledge of “Parameterized Cursor” and “Cursor For Loop” beforehand. So for better understanding I highly suggest you to check out the respective blogs to learn the concepts.
The question which was left unattended in the previous tutorial was how to create a cursor for loop with a parameterized cursor in Oracle database? Hence today in this PL/SQL tutorial we will learn how to create cursor for loop with parameterized cursor.
Using cursor for loop, working with parameterized cursor is as easy as working with simple explicit cursor. Checkout the example given below.
Example1. Cursor For Loop With Parameterized Cursor
DECLARE CURSOR cur_RebellionRider( var_e_id NUMBER) IS SELECT first_name, employee_id FROM employees WHERE employee_id > var_e_id; BEGIN FOR l_idx IN cur_RebellionRider(200) LOOP DBMS_OUTPUT.PUT_LINE(l_idx.employee_id||' '||l_idx.first_name); END LOOP; END;
You can pass the values for the parameters of your cursor just by simply writing the argument right after the name of your cursor in loop statement as shown in the above example (Statement In bold). Always remember to enclose the arguments inside the parenthesis.
Read the previous blog and find out how to create a cursor for loop with Inline Cursor declaration.
That’s it for today on cursor for loop with parameterized cursor. Do make sure to share this blog with your friends and colleagues on your Facebook or other social media.
Remember now you can win RebellionRider merchandise bag by sharing the content, just make sure to tag me.