Example for %ROWCOUNT

Following is a PLSQL block which updates the result of a students and gives the number of students whose result are in withheld state.

stu_mstr
————–
result branch_no
W 21
F 22
W 21
P 21

branch_mstr
————-
branch_no name
21 computers
22 electronics

DECLARE
rows_affected CHAR(4);
BEGIN
UPDATE stu_mstr SET result='P' WHERE result = 'W' AND
branch_no IN (SELECT branch_no FROM branch_mstr
WHERE name='computers');
rows_affected:=TO_CHAR(SQL%rowcount);
IF SQL%rowcount>0 THEN
DBMS_OUTPUT.put_line(rows_affected||'results updated successfully');
ELSE
DBMS_OUTPUT.put_line('there are no withheld results for computers');
END IF;
END;

OUTPUT
2 results updated successfully

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.