PL/SQL Exceptions on Update/Delete of non-existing row

后端 未结 3 901
太阳男子
太阳男子 2021-02-19 10:10

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         


        
相关标签:
3条回答
  • 2021-02-19 10:39

    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.

    0 讨论(0)
  • 2021-02-19 10:55

    to do so you need to use

    IF SQL%ROWCOUNT = 0 THEN
        RAISE no_delete;
    END IF;
    

    and define your

    0 讨论(0)
  • 2021-02-19 11:01

    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.

    0 讨论(0)
提交回复
热议问题