create or replace trigger S_INSERT_CUSTBANK before insert on bd_custbank for each row declare pk_bas char(20); vname varchar2(80); cursor basjob(id char) is select pk_custbank from ncv5.bd_custbank /*目标数据库表*/ where pk_custbank = id and nvl(dr, 0) = 0; begin /*判断数据是否在目标数据库存在*/ open basjob(:new.pk_custbank); loop fetch basjob into pk_bas; exit when basjob%notfound; end loop; close basjob; /******************************/ if pk_bas is null then begin select custname into vname from bd_cubasdoc where pk_cubasdoc = :new.pk_cubasdoc; update bd_accbank set combineaccnum = :new.memo, unitname = vname, city = :new.accaddr, bankarea = :new.accaddr where pk_accbank = :new.pk_accbank; insert into ncv5.bd_custbank /*目标数据库表*/ (pk_custbank, pk_cubasdoc, accname, account, accaddr, defflag, memo, pk_accbank, pk_corp, pk_currtype, ts, dr) values (:new.pk_custbank, :new.pk_cubasdoc, :new.accname, :new.account, :new.accaddr, :new.defflag, :new.memo, :new.pk_accbank, :new.pk_corp, :new.pk_currtype, :new.ts, :new.dr); end; end if; end addbd_custbank;
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)