What will you get by the cursor attribute SQL%ROWCOUNT?

The cursor attribute SQL%ROWCOUNT will return the number of rows that are processed by a SQL statement.

In PL/SQL, the cursor attribute SQL%ROWCOUNT returns the number of rows that were affected by the most recent SQL statement executed. It is often used to determine how many rows were affected by operations like INSERT, UPDATE, or DELETE in a cursor or a block of PL/SQL code.

For example, after executing an UPDATE statement, you can use SQL%ROWCOUNT to find out how many rows were actually updated by that statement. Here’s a simple example:

DECLARE
rows_updated NUMBER;
BEGIN
UPDATE your_table
SET your_column = 'new_value'
WHERE your_condition;
rows_updated := SQL%ROWCOUNT;

DBMS_OUTPUT.PUT_LINE(‘Number of rows updated: ‘ || rows_updated);
END;

In this example, SQL%ROWCOUNT will give you the number of rows that were updated by the UPDATE statement. It is important to note that SQL%ROWCOUNT is specific to the most recent SQL statement, so if you have multiple SQL statements in your block, the value of SQL%ROWCOUNT will be related to the last one executed.

Keep in mind that SQL%ROWCOUNT is not applicable to queries that retrieve data (e.g., SELECT statements) as it reflects only the number of affected rows in DML (Data Manipulation Language) operations.