select
bd_accid.accidcode,
gl_freevalue.valuecode
from fts_voucher_b, bd_accsubj, gl_freevalue, bd_accid
where fts_voucher_b.pk_subject = bd_accsubj.pk_accsubj
and fts_voucher_b.pk_ass = gl_freevalue.freevalueid
and fts_voucher_b.dr = '0'
and fts_voucher_b.pk_corp = '1162'
and fts_voucher_b.pk_account = bd_accid.pk_accid
and length(gl_freevalue.valuecode) = '6'
and substr(gl_freevalue.valuecode, 0, 1) = '0'
and bd_accid.accidcode != gl_freevalue.valuecode
create or replace trigger CHECK_VOUCHER
before insert or update on fts_voucher
for each row
declare
-- local variables here
pk_bas char(20);
accode char(6);
vcode char(6);
cursor basjob(id char) is
select fts_voucher_b.pk_voucher,bd_accid.accidcode, gl_freevalue.valuecode
from fts_voucher_b,bd_accid, gl_freevalue
where fts_voucher_b.pk_voucher = id
and fts_voucher_b.pk_ass = gl_freevalue.freevalueid
and fts_voucher_b.pk_account = bd_accid.pk_accid
and length(gl_freevalue.valuecode) = '6'
and substr(gl_freevalue.valuecode, 0, 1) = '0';
begin
open basjob(:new.pk_voucher);
loop
fetch basjob
into pk_bas, accode , vcode;
exit when basjob%notfound;
--raise_application_error(-20001,pk_accidcode||'hhh');
end loop;
close basjob;
if pk_bas is not null then
if accode<>vcode then
begin
raise_application_error(-20001,'结算凭证号'||:new.cent_typeid||'账户和客商不一致,请修改!');
end;
end if;
end if;
end CHECK_VOUCHER;