Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question.

Asked: July 02, 2016 - 1:02 pm UTC

Last updated: July 03, 2016 - 3:42 am UTC

Version: 11.0

Viewed 1000+ times

You Asked

1)After updating on complex view by using instead of trigger which table will affect first and why.

and Connor said...

The trigger takes control of the ENTIRE ddl. So it can anything that *you* specify.

For example, here's one that does NOTHING with the original data ...


SQL> drop table t purge;

Table dropped.

SQL> create table t as
  2  select mod(rownum,100) x, rownum y
  3  from dual
  4  connect by level <= 100000;

Table created.

SQL>
SQL> create or replace
  2  view V as
  3  select x, sum(y) tot_y
  4  from t
  5  group by x;

View created.

SQL>
SQL>
SQL> drop table t1 purge;

Table dropped.

SQL> create table t1 ( a date, b int );

Table created.

SQL>
SQL> create or replace
  2  trigger trg
  3  instead of insert or update or delete
  4  on v
  5  begin
  6    insert into t1 values (sysdate,1);
  7  end;
  8  /

Trigger created.

SQL>
SQL> insert into v values (1,2);

1 row created.

SQL> select * from t1;

A                  B
--------- ----------
03-JUL-16          1

1 row selected.

SQL> delete from v;

100 rows deleted.

SQL> select * from t1;

A                  B
--------- ----------
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1
03-JUL-16          1

101 rows selected.

SQL>


So they can be very dangerous in terms of not providing a "sensible" result if you are not careful.

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library