· 9 years ago · Oct 28, 2016, 06:58 PM
1---------------------------------------------
2| PK | Name | Address | Postal Code |
3---------------------------------------------
4| 1 | AA | Street1 | 11111 |
5| 2 | BB | Street2 | 22222 |
6| 3 | CC | Street3 | 33333 |
7---------------------------------------------
8
9---------------------------------------------
10| PK | Name | Address | Postal Code |
11---------------------------------------------
12| 1 | AA | Street1 | 11111 |
13| 2 | BB | Street2 | 44444 |
14| 3 | CC | Dtreet7 | 33333 |
15---------------------------------------------
16
17---------------------------------------------
18| PK | Name | Address | Postal Code |
19---------------------------------------------
20| 2 | | | 44444 |
21| 3 | | Dtreet7 | |
22---------------------------------------------
23
24CREATE OR REPLACE TRIGGER vr_reporting_trigger
25 AFTER UPDATE ON orig_tab
26 FOR EACH ROW
27BEGIN
28IF inserting THEN
29INSERT INTO rep_tab(pk, name, address, code)
30 SELECT :new.pk, :new.name, :new.address, :new,code FROM DUAL
31 WHERE NOT EXISTS (SELECT 1 FROM rep_tab WHERE pk = :new.pk);
32UPDATE rep_tab t SET t.name = :new.name, t.address = :new.address, t.code = :new.code
33 WHERE t.pk = :new.pk;
34ELSIF updating THEN
35IF :new.pk <> :old.pk THEN
36 UPDATE rep_tab t
37 SET t.name = :new.name, t.address = :new.address, t.code =: new.code
38 WHERE t.pk = :old.pk ;
39 END IF;
40 MERGE INTO rep_tab d
41 USING DUAL ON (d.pk = :old.pk)
42 WHEN MATCHED THEN
43 UPDATE SET d.name = :new.name, d.address = :new.address, d.code =: new.code
44 WHEN NOT MATCHED THEN
45 INSERT (d.pk,d.name, d.address, d.code) VALUES (:new.pk,:new.name, new.address, new.code);
46END IF;
47END;
48
49---------------------------------------------
50| PK | Name | Address | Postal Code |
51---------------------------------------------
52| 2 | BB | Street2 | 44444 |
53| 3 | CC | Dtreet7 | 33333 |
54---------------------------------------------
55
56CREATE OR REPLACE TRIGGER ...
57... UPDATE OF Sal, Comm ON Emp_tab ...
58BEGIN
59
60... IF UPDATING ('SAL') THEN ... END IF;
61
62END;
63
64PLS-00103: Encountered the symbol "`" when expecting one of the
65 following:
66 ( ) - + case mod new not null <an identifier>
67 <a double-quoted delimited-identifier> <a bind variable>
68 table continue avg count current exists max min prior sql
69 stddev sum variance execute multiset the both leading
70 trailing forall merge year month day hour minute second
71 timezone_hour timezone_minute timezone_region timezone_abbr
72 time timestamp interval date
73 <a string literal with character set specification>