What is implicit cursor in Oracle? -
A session contains a single implicit cursor which is defined automatically by PL/SQL.
The cursor gets assigned to represent the execution of a statement whenever it is executed.
Following are the attributes of the implicit cursor:
Attribute Status Condition
SQL%FOUND TRUE if the SQL statement has changed any rows
SQL%NOTFOUND TRUE if the SQL statement has not changed any rows
SQL%ROWCOUNT - The number of rows affected by the SQL statement
%ISOPEN TRUE if there is a SQL statement being associated to the cursor.
DECLARE var_rows number(5);
BEGIN
UPDATE employees
SET salary = salary + 1000;
IF SQL%NOTFOUND THEN
dbms_output.put_line('None of the salaries where updated');
ELSIF SQL%FOUND THEN
var_rows := SQL%ROWCOUNT;
dbms_output.put_line('Salaries for ' || var_rows || 'employees are updated');
END IF;
END;
Output:-
Salaries for 107 employees are updated
PL/SQL procedure successfully completed.
In the above PL/SQL Block, the salaries of all the employees in the ‘employee’
table are updated. If none of the employee’s salary are updated
we get a message 'None of the salaries where updated'.
Else we get a message like for example, 'Salaries for 107 employees are updated' if there are 107 rows in ‘employee’ table.
A session contains a single implicit cursor which is defined automatically by PL/SQL.
The cursor gets assigned to represent the execution of a statement whenever it is executed.
Following are the attributes of the implicit cursor:
Attribute Status Condition
SQL%FOUND TRUE if the SQL statement has changed any rows
SQL%NOTFOUND TRUE if the SQL statement has not changed any rows
SQL%ROWCOUNT - The number of rows affected by the SQL statement
%ISOPEN TRUE if there is a SQL statement being associated to the cursor.
DECLARE var_rows number(5);
BEGIN
UPDATE employees
SET salary = salary + 1000;
IF SQL%NOTFOUND THEN
dbms_output.put_line('None of the salaries where updated');
ELSIF SQL%FOUND THEN
var_rows := SQL%ROWCOUNT;
dbms_output.put_line('Salaries for ' || var_rows || 'employees are updated');
END IF;
END;
Output:-
Salaries for 107 employees are updated
PL/SQL procedure successfully completed.
In the above PL/SQL Block, the salaries of all the employees in the ‘employee’
table are updated. If none of the employee’s salary are updated
we get a message 'None of the salaries where updated'.
Else we get a message like for example, 'Salaries for 107 employees are updated' if there are 107 rows in ‘employee’ table.
0 comments:
Post a Comment