为了做到这一点,我认为您只需要一个触发器?
CREATE OR REPLACE TRIGGER ins_his BEFORE UPDATE OF datetime ON main
FOR EACH ROW
BEGIN
INSERT INTO hist ( col2 , col3 )
VALUES ( :new.col2, :new.col3 );
:new.col2 := NULL;
:new.col3 := NULL;
END;
/
示例输出:
SQL*Plus: Release 11.2.0.1.0 Production on Tue Dec 17 13:17:08 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management,
OLAP,
Data Mining and Real Application Testing options
SQL> create table main ( datetime DATE, col2 NUMBER, col3 NUMBER );
Table created.
SQL> create table hist ( col2 NUMBER, col3 NUMBER );
Table created.
SQL> CREATE OR REPLACE TRIGGER ins_his BEFORE UPDATE OF datetime ON main
2 FOR EACH ROW
3 BEGIN
4 --
5 INSERT INTO hist ( col2 , col3 )
6 VALUES ( :new.col2, :new.col3 );
7 --
8 :new.col2 := NULL;
9 :new.col3 := NULL;
10 --
11 END;
12 /
Trigger created.
SQL> insert into main( datetime, col2, col3 )
2 values ( sysdate, 5, 10 );
1 row created.
SQL> select * from main;
DATETIME COL2 COL3
--------- ---------- ----------
17-DEC-13 5 10
SQL> select * from hist;
no rows selected
SQL> update main set datetime = sysdate-1;
1 row updated.
SQL> select * from main;
DATETIME COL2 COL3
--------- ---------- ----------
16-DEC-13
SQL> select * from hist;
COL2 COL3
---------- ----------
5 10
SQL>