It returns the Boolean value TRUE if at least one row was processed.
In PL/SQL, the cursor attribute SQL%FOUND
is used to check whether the last SQL operation (query) on a cursor returned at least one row. If the most recent fetch or execute on the cursor returned one or more rows, then SQL%FOUND
will be TRUE; otherwise, it will be FALSE.
Here’s an example of how it might be used in a cursor loop:
DECLARE
CURSOR my_cursor IS
SELECT column1, column2 FROM my_table;
my_variable my_table.column1%TYPE;BEGIN
OPEN my_cursor;
LOOP
FETCH my_cursor INTO my_variable;
EXIT WHEN my_cursor%NOTFOUND; — Exit loop when no more rows
— Process the data here
DBMS_OUTPUT.PUT_LINE(‘Value of column1: ‘ || my_variable);
END LOOP;
CLOSE my_cursor;
END;
In this example, SQL%FOUND
is not explicitly used, but it could be used in the loop to check whether the last fetch returned any rows. If the loop were to check IF my_cursor%FOUND
, it would mean the same thing.
Remember that %FOUND
is only valid immediately after a fetch or execute and before the next fetch or execute on the cursor.