What is Parameterized cursor
What is Parameterized cursor
Unlike simple explicit cursor, parameterized cursors accept values as parameter. You
specify the list of parameters separated by comma (,) while declaring the cursor and
supply the corresponding argument for each parameter in the list while opening the
cursor.
Definition:
Cursor parameter can be appropriately defined as an explicit cursor that accepts
arguments from the user in the form of parameter.
PL/SQL Parameterized cursor define only datatype of parameter and not need to
define its length.
Default values is assigned to the Cursor parameters. and scope of the parameters are
locally.
Parameterized cursors are also saying static cursors that can passed parameter value
when cursor are opened.
There are few things which you have to take care of while specifying the parameters
in your explicit cursor.
You can use a parameter and then pass different values to the WHERE clause each
time a cursor is opened instead of hardcoding a value into the WHERE clause of a
query to select particular information.
When you pass parameters instead of hardcoding the values, the result set for that
cursor is not tied to a specific variable in a program or block. Therefore in case your
program has nested blocks, you can define the cursor at a higher-level (enclosing)
block and use it in any of the sub-blocks with variables defined in those local blocks.
You must be wondering when we need a cursor with parameters in our PL/SQL.
The simplest answer is whenever you need to use your cursor in more than one place
with different values for the same WHERE clause of your SELECT statement.
If you can add something to this and have another idea for using a parameterized
cursor. Then I am always open to listening to your thoughts do make sure to share it
with me on my Facebook or twitter.
DECLARE
--Declare Cursor
WHERE employee_id<var_e_id;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_name );
END LOOP;
CLOSE p_cur_RebellionRider;
END;
%TYPE : Used to declare a field with the same type as that of a specified table's
column.
DECLARE
vEmployeeNameEmployee.Name%TYPE;
BEGIN
SELECT Name
INTO vEmployeeName
FROM Employee
WHERE RowNum = 1;
DBMS_OUTPUT.PUT_LINE(vEmployeeName);
END;
/
%ROWTYPE: Used to declare a record with the same types as found in the specified
table, view or cursor (= multiple columns).
DECLARE
rEmployeeEmployee%ROWTYPE;
BEGIN
rEmployee.Name := 'Matt';
rEmployee.Age := 31;
DBMS_OUTPUT.PUT_LINE(rEmployee.Name);
DBMS_OUTPUT.PUT_LINE(rEmployee.Age);
END;
/