博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
复杂查询的触发器怎么写啊(账户,客商)3.15更新|最终完成|
阅读量:4971 次
发布时间:2019-06-12

本文共 4969 字,大约阅读时间需要 16 分钟。

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 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;

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 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 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;

转载于:https://www.cnblogs.com/sumsen/archive/2012/05/29/2524822.html

你可能感兴趣的文章
[Voice communications] 声音的滤波
查看>>
BZOJ.3139.[HNOI2013]比赛(搜索 Hash)
查看>>
json在线解析
查看>>
存储设备形成的层次结构
查看>>
源码阅读 - java.util.concurrent (三)ConcurrentHashMap
查看>>
Daily Scrum 10.30
查看>>
SQL语言之概述(一)
查看>>
数据库表 copy
查看>>
LinkedList源码解析
查看>>
SignalR循序渐进(一)简单的聊天程序
查看>>
MyServer
查看>>
Learning Cocos2d-x for XNA(2)——深入剖析Hello World
查看>>
软件建模——第9章 毕业论文管理系统—面向对象方法
查看>>
Http协议
查看>>
手机端web开发必备代码
查看>>
[SDOI2008]洞穴勘测
查看>>
NOI2014 购票
查看>>
Difference between Linearizability and Serializability
查看>>
电影《绿皮书》
查看>>
IDEA使用操作文档
查看>>