Oracle's syntax for creating a trigger based on two tables : Create Trigger « Trigger « Oracle PL / SQL






Oracle's syntax for creating a trigger based on two tables

  

SQL>
SQL>
SQL>
SQL> CREATE TABLE myTable1 (a INTEGER, b CHAR(10));

Table created.

SQL>
SQL> CREATE TABLE myTable2 (c CHAR(10), d INTEGER);

Table created.

SQL>
SQL>
SQL> CREATE TRIGGER trig1
  2      AFTER INSERT ON myTable1
  3      REFERENCING NEW AS newRow
  4      FOR EACH ROW
  5      WHEN (newRow.a <= 10)
  6      BEGIN
  7          INSERT INTO myTable2 VALUES(:newRow.b, :newRow.a);
  8      END trig1;
  9  

Trigger created.

SQL>
SQL> insert into myTable1 values(1,'a');

1 row created.

SQL> insert into myTable1 values(2,'b');

1 row created.

SQL>
SQL> select * from myTable1;

         A B
---------- ----------
         1 a
         2 b

SQL> select * from myTable2;

C                   D
---------- ----------
a                   1
b                   2

SQL>
SQL> drop table myTable1;

Table dropped.

SQL> drop table myTable2;

Table dropped.

SQL>

           
         
    
  








Related examples in the same category

1.create or replace trigger
2.Trigger on each row
3.Use Sequence in a trigger
4.Empty trigger(before insert or update or delete)
5.Create tigger on wrapper table
6.This trigger sends messages over a pipe to record inserts into myStudent.
7.Cascade inserts into myStudent into session and lecturer.
8.Trigger is autonomous and hence the changes will be logged even if the original transaction rolls back.
9.Trigger Which Modifies a Mutating Table
10.Creating a Trigger with cursor inside
11.Autonumbering Trigger
12.Use RAISE_APPLICATION_ERROR in a trigger
13.Show errors for a trigger
14.Submit job from a trigger
15.Use sysdate and user function in a trigger