How to prevent Insert trigger from starting when no row is inserted?

I have TABLE 1. In this table I created a trigger: AFTER INSERT OR UPDATE OR DELETE

Now, if I do an insert that doesn't insert anything, the trigger will still fire:

insert into TABLE1 select * from TABLE1 where 1=0;

This request will insert NO ROWS, but still the trigger still fires.

Is there any way to avoid this? Is this normal behavior?

+3
source share
3 answers

Yes, this is normal behavior. It can be avoided, although this requires three triggers:

  • BEFORE a trigger to set a boolean package variable to FALSE
  • A FOR EACH ROW trigger to set the variable to TRUE when inserting a row
  • AFTER, .

? , : ?

+4

, Oracle , INSERT, AFTER INSERT, . AFTER , - . :)

, :

  • mypackage.table1_nb_ins 0
  • AFTER INESRT ROW

AFTER INSERT, 0

+3

A row trigger is triggered every time a trigger statement affects a table. For example, if an UPDATE statement updates multiple rows in a table, a row trigger is fired once for each row affected by the UPDATE statement. If the trigger statement does not affect the rows, the row trigger does not start.

https://docs.oracle.com/cd/B19306_01/server.102/b14220/triggers.htm

0
source

Source: https://habr.com/ru/post/1751757/


All Articles