限售触发器(写触发器参考)

CREATE OR REPLACE TRIGGER TRI_Mg_LockShares
  before insert or update on TBL_CHN_T_Mg_LockShares
  for each row

declare
  msgNum number(10);
begin
  --InstitutionID  上市公司ID
  if INSERTING then
    select InstitutionID
      into :new.InstitutionID
      from INPUT.TBL_CHN_I_CO_STOCKINFO@Input_52
     where SYMBOL = :new.SYMBOL
       and UPDATESTATE <= 1
       and rownum = 1;
--FullName  股东名称
    if instr(:new.FullName, '?') > 0 then
      :new.FullName := replace(:new.FullName, '?', '·');
    end if;
    if regexp_instr(:new.reason, '(首发后)+.*(限售)+') > 0 then
      select count(FullName)
        into msgNum
        from TBL_CHN_T_Mg_LockShares a
       where a.updatestate <= 1
         and a.FullName = :new.FullName
         and a.Symbol = :new.symbol
         and FullName in (select FullName
                            from TBL_CHN_T_Mg_IpoShr
                           where updatestate <= 1);
--reason  限售原因
      if msgNum > 0 then
        select '首发原股东' into :new.reason from dual;
      else
        select '非公开增发' into :new.reason from dual;
      end if;
    elsif regexp_instr(:new.reason, '(追加承诺)+') > 0 then
      select count(FullName)
        into msgNum
        from TBL_CHN_T_Mg_LockShares a
       where a.updatestate <= 1
         and a.FullName = :new.FullName
         and a.Symbol = :new.symbol
         and FullName in (select FullName
                            from TBL_CHN_T_Mg_IpoShr
                           where updatestate <= 1);

      if msgNum > 0 then
        select '首发原股东' into :new.reason from dual;
      else
        select '其他' into :new.reason from dual;
      end if;
    end if;

--reasonid  限售原因编码
    select replace(replace(replace(replace(replace(replace(replace(replace(replace(:new.Reason,
                                                                                   '非公开增发',
                                                                                   'P6403'),
                                                                           '公开增发',
                                                                           'P6404'),
                                                                   '其他',
                                                                   'P6409'),
                                                           '股权激励',
                                                           'P6408'),
                                                   '高管限售',
                                                   'P6407'),
                                           '股权分置改革',
                                           'P6406'),
                                   '配股',
                                   'P6405'),
                           '首发网下配售',
                           'P6402'),
                   '首发原股东',
                   'P6401')
      into :new.reasonid
      from dual;

--beginningshares  期初持有数量
    if :new.beginningshares is null then
      select '0' into :new.beginningshares from dual;
    end if;


--addshares  本期增加限售股数
    if :new.addshares is null then
      select '0' into :new.addshares from dual;
    end if;


--listedshares  本期解禁数量
    if :new.listedshares is null then
      select '0' into :new.listedshares from dual;
    end if;

--endshares  期末持有限售股数
    if :new.endshares is null then
      select '0' into :new.endshares from dual;
    end if;

  end if;

end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值