I am learning PL/SQL these days and currently working with Procedures and exceptions using oracle HR schema.
Here is my simple procedure.
create or rep
I believe SQL%NOTFOUND
returns true
when no records are found. Your IF
would evaluate to true in that case, and therefore write your put_line to terminal. The SQL statement executed successfully. If you execute that SQL statement by itself from command line, you will receive 0 rows updated/deleted, not an Oracle error.
If you want to have an exception thrown, you could use RAISE
inside your IF
and point it to the exception in the exception block you want to have thrown.
to do so you need to use
IF SQL%ROWCOUNT = 0 THEN
RAISE no_delete;
END IF;
and define your
There is no "exception" - the sql executed successfully. It successfully deleted every record that matched the criteria...which was 0 records. Same thing if a similar update statement was executed. You used the SQL%NOTFOUND to determine there were no records that were affected, but this does not mean there was an "exception".
Perhaps you're thinking of the NO_DATA_FOUND Exception raised if you try a "select into" clause and it doesn't find any matching records.