select fts_voucher_b.interestdate,
fts_voucher_b.summary,
bd_accsubj.dispname,
fts_voucher_b.debitamount 借方,
fts_voucher_b.creditamount 贷方,
bd_accid.accidcode,
bd_accid.accidname,
gl_freevalue.valuecode,
gl_freevalue.valuename
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
order by fts_voucher_b.interestdate
就是这个红色加粗的,希望在触发器完成。
研究到现在,发现三张表查询之后:new不能传递
create or replace trigger add_js
before insert on fts_voucher_b
for each row
declare
-- local variables here
pk_voucherid char(20);
pk_accidcode char(6);
pk_valuecode char(6);
cursor basjob(id char) is
select
fts_voucher_b.pk_voucher_b,
bd_accid.accidcode,
gl_freevalue.valuecode
from fts_voucher_b, gl_freevalue, bd_accid
where 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 fts_voucher_b.pk_voucher_b=id
and nvl(fts_voucher_b.dr, 0) = 0;
begin
open basjob(:new.pk_voucher_b);
loop
fetch basjob
into pk_voucherid,pk_accidcode,pk_valuecode;
exit when basjob%notfound;
--raise_application_error(-20001,pk_accidcode||'hhh');
end loop;
close basjob;
raise_application_error(-20001,pk_voucherid||'hhh');
if pk_accidcode<>pk_valuecode then
begin
raise_application_error(-20001, '已从网银付款,不能修改名称,请取消!');
end;
end if;
end add_js;
再次更新:如果能通过审核结算凭证的时候触发就行了,可是查询fts_checkvoucher是空,omg
2.24 凌晨0:32更新,完成ultimate:
create or replace trigger CHECK_VOUCHER
before insert or update on fts_voucher
for each row
declare
-- local variables here
pk_bas char(20);
cursor basjob(id char) is
select pk_voucher
from fts_voucher_b
where pk_voucher = id
and pk_voucher in
(select fts_voucher_b.pk_voucher
from fts_voucher_b, gl_freevalue, bd_accid
where 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'
and bd_accid.accidcode <> gl_freevalue.valuecode);
begin
open basjob(:new.pk_voucher);
loop
fetch basjob
into pk_bas;
exit when basjob%notfound;
--raise_application_error(-20001,pk_accidcode||'hhh');
end loop;
close basjob;
if pk_bas is not null then
begin
raise_application_error(-20001,
'审核的结算凭证账户和客商不一致,请修改!');
end;
end if;
end CHECK_VOUCHER;
2.24上午9:14更新结算凭号:
raise_application_error(-20001,'审核的结算凭证'||:new.cent_typeid||'账户和客商不一致,请修改!');11:40 更新第二中写法:
create or replace trigger CHECK_VOUCHER
before insert or update on fts_voucher for each rowdeclare -- 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;2.27号更新错误提示的样式:
raise_application_error(-20001,'结算凭证号:'||:new.cent_typeid|| ' 账户和客商不一致,请修改!');
ps:这里空格必须增加在‘’之中,否则系统虽然执行不报错,但是空格并没有起作用。
3.15更新:
今天太诡异了,审核没有报错,可是我在日结的时候居然报错,并且是结算凭证号76,可是今天的结算凭证根本没有76,然后我查询所有76号的凭证,发现有十几个,果然在2010年有一个总部和北京公司账户和客商对不上的。
奇怪,诡异,这个触发器怎么检查那么久远的东西?
没关系,稍微更新一下触发器就行了:
create or replace trigger CHECK_VOUCHER
before insert or update on fts_voucher for each rowdeclare -- local variables here pk_bas char(20); cursor basjob(id char) is select pk_voucher from fts_voucher_b where pk_voucher = id and pk_voucher in (select fts_voucher_b.pk_voucher from fts_voucher_b, gl_freevalue, bd_accid where 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' and fts_voucher_b.interestdate>'2010-12-31' and bd_accid.accidcode <> gl_freevalue.valuecode); begin open basjob(:new.pk_voucher); loop fetch basjob into pk_bas; exit when basjob%notfound; --raise_application_error(-20001,pk_accidcode||'hhh'); end loop; close basjob; if pk_bas is not null then begin raise_application_error(-20001,'结算凭证号:'||:new.cent_typeid|| ' 账户和客商不一致,请修改!'); end; end if;end CHECK_VOUCHER;