1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
create
or
replace
trigger
DATA_SYNC_@
TABLE
@
before
insert
or
update
or
delete
on
@
TABLE
@
REFERENCING OLD
AS
old_emp NEW
AS
new_emp
for
each row
begin
--通过应用程序修改时,F_SYNC_UPDATE=null或F_SYNC_UPDATE=0,此时不需要更新F_SYNC_DATE 时间戳,也不需要记录删除记录
if (:new_emp.F_SYNC_UPDATE
is
null
)
or
(:new_emp.F_SYNC_UPDATE = 0)
then
--插入和更新操作,更新时间戳F_SYNC_DATE=systimestamp和F_SYNC_UPDATE=null
if INSERTING
or
UPDATING
then
select
systimestamp,
null
into
:new_emp.F_SYNC_DATE, :new_emp.F_SYNC_UPDATE
from
dual;
end
if;
if INSERTING
then
--把新增加的记录插入到操作记录表
insert
into
DATA_SYNC_B_OPERATOR
(t_name, o_type, o_date, VKEYS)
values
(
'@TABLE@'
, 1, systimestamp, @INSERTVAL@);
end
if;
if DELETING
then
--把删除记录的主键添加到操作记录表
insert
into
DATA_SYNC_B_OPERATOR
(t_name, o_type, o_date, VKEYS)
values
(
'@TABLE@'
, 3, systimestamp, @UPDATEVAL@);
end
if;
end
if;
end
DATA_SYNC_@
TABLE
@;
|
本文转自 乌英达姆 51CTO博客,原文链接:http://blog.51cto.com/7156680/1790837