基础资料 部门触发器的遇到 实体化视图问题,走过路过来...
660次浏览
编辑于2017年08月23日 09:18:44
做一个 数据库A 到 数据库B的数据同步,基本思路就是 给需要同步的表在A中做触发器,每次审核单据后 insert到数据库B中。在做 基础数据,部门,银行时都遇到了这个问题,但是计量单位是没有这个错误的,可以实现单据在审核后,同步到数据库B中。
下面以【银行表为例】,写的触发器,提示 实体化视图问题
代码如下:
create or replace trigger bankupdate
after update on t_bd_bank
for each ROW
--银行 审核后出发
declare
PRAGMA AUTONOMOUS_TRANSACTION;
v_banknumber NUMBER;
v_isnumber NUMBER;
v_newbank NUMBER;
begin
IF :new.Fdocumentstatus='C' THEN
--判断这个单子是否在目标表存在
SELECT COUNT(*) INTO v_isnumber FROM t_bd_bank@ADMIN2TOADMIN1 tb
WHERE ABS(tb.fbankid)=:NEW.fbankid AND tb.fnumber=:new.Fnumber;
IF v_isnumber=0 THEN --表示不存在时
v_newbank:=:new.Fbankid;
--存在fbankid一样,fnumber不一样的情况
SELECT COUNT(*) INTO v_banknumber FROM t_bd_bank@ADMIN2TOADMIN1 tb
WHERE ABS(tb.fbankid)=:NEW.fbankid AND tb.fnumber!=:new.Fnumber;
IF v_banknumber=1 THEN
v_newbank:=:new.Fbankid*(-1);
END IF;
--insert银行
INSERT INTO t_bd_bank@ADMIN2TOADMIN1
(
fbankid,
fmasterid,
fstartdate,
fenddate,
fdocumentstatus,
fforbidstatus,
fcreateorgid,
fuseorgid,
fcreatorid,
fcreatedate,
fmodifierid,
fmodifydate,
fauditorid,
fauditdate,
fforbidderid,
fforbiddate,
fissyspreset,
fnumber,
faddress,
facntareacode,
fbanktype,
fdistrict,
fprovince,
fcity,
facntbranchnumber
)
SELECT
v_newbank,
v_newbank,
fstartdate,
fenddate,
'C',
fforbidstatus,
fcreateorgid,
fuseorgid,
fcreatorid,
fcreatedate,
fmodifierid,
fmodifydate,
fauditorid,
fauditdate,
fforbidderid,
fforbiddate,
fissyspreset,
fnumber,
faddress,
facntareacode,
fbanktype,
fdistrict,
fprovince,
fcity,
facntbranchnumber
FROM t_bd_bank
WHERE fbankid=:new.Fbankid;
--多语言表
INSERT INTO t_bd_bank_l@admin2toadmin1(
fpkid,
fbankid,
flocaleid,
fname,
fdescription,
facntareaname
)
SELECT
fpkid,
v_newbank,
flocaleid,
fname,
fdescription,
facntareaname
FROM t_Bd_Bank_l
WHERE fbankid=:new.Fbankid;
END IF;
END IF;
COMMIT;
end bankupdate;
下面以【银行表为例】,写的触发器,提示 实体化视图问题
代码如下:
create or replace trigger bankupdate
after update on t_bd_bank
for each ROW
--银行 审核后出发
declare
PRAGMA AUTONOMOUS_TRANSACTION;
v_banknumber NUMBER;
v_isnumber NUMBER;
v_newbank NUMBER;
begin
IF :new.Fdocumentstatus='C' THEN
--判断这个单子是否在目标表存在
SELECT COUNT(*) INTO v_isnumber FROM t_bd_bank@ADMIN2TOADMIN1 tb
WHERE ABS(tb.fbankid)=:NEW.fbankid AND tb.fnumber=:new.Fnumber;
IF v_isnumber=0 THEN --表示不存在时
v_newbank:=:new.Fbankid;
--存在fbankid一样,fnumber不一样的情况
SELECT COUNT(*) INTO v_banknumber FROM t_bd_bank@ADMIN2TOADMIN1 tb
WHERE ABS(tb.fbankid)=:NEW.fbankid AND tb.fnumber!=:new.Fnumber;
IF v_banknumber=1 THEN
v_newbank:=:new.Fbankid*(-1);
END IF;
--insert银行
INSERT INTO t_bd_bank@ADMIN2TOADMIN1
(
fbankid,
fmasterid,
fstartdate,
fenddate,
fdocumentstatus,
fforbidstatus,
fcreateorgid,
fuseorgid,
fcreatorid,
fcreatedate,
fmodifierid,
fmodifydate,
fauditorid,
fauditdate,
fforbidderid,
fforbiddate,
fissyspreset,
fnumber,
faddress,
facntareacode,
fbanktype,
fdistrict,
fprovince,
fcity,
facntbranchnumber
)
SELECT
v_newbank,
v_newbank,
fstartdate,
fenddate,
'C',
fforbidstatus,
fcreateorgid,
fuseorgid,
fcreatorid,
fcreatedate,
fmodifierid,
fmodifydate,
fauditorid,
fauditdate,
fforbidderid,
fforbiddate,
fissyspreset,
fnumber,
faddress,
facntareacode,
fbanktype,
fdistrict,
fprovince,
fcity,
facntbranchnumber
FROM t_bd_bank
WHERE fbankid=:new.Fbankid;
--多语言表
INSERT INTO t_bd_bank_l@admin2toadmin1(
fpkid,
fbankid,
flocaleid,
fname,
fdescription,
facntareaname
)
SELECT
fpkid,
v_newbank,
flocaleid,
fname,
fdescription,
facntareaname
FROM t_Bd_Bank_l
WHERE fbankid=:new.Fbankid;
END IF;
END IF;
COMMIT;
end bankupdate;
推荐阅读