触发器语句

create --新建触发器
or --或者
replace --替换触发器
trigger --触发
tri_out_ta_presc_d_t --触发器名称
after | before --跟新后 | 跟新前
insert | update | delete --增加 |修改 |删除
on hisdb.out_ta_presc_d_t --触发表名称
for each row
执行语句
declare --申明变量

create or replace trigger tri_out_ta_presc_d_t after insert
on hisdb.out_ta_presc_d_t for each row
declare
ll_count number;
ll_count1 number;
ls_sbrlsh varchar2(20);
ls_jmxlh varchar2(100);
begin
select count(1) into ll_count
from med_td_info tinfo
where tinfo.sypbm = :new.sypdm
and tinfo.sypmc=:new.sypmc
and tinfo.sypgg = :new.sypgg
and tinfo.sdlflbm in (‘D’,‘C’);
if ll_count is null then ll_count := 0; end if;
if ll_count > 0 then
select sbrls into ls_sbrlsh from out_ta_presc_m_t where scfh = :new.scfh;
if ls_sbrlsh is null then ls_sbrlsh := ‘NULL’; end if;
select count(1) into ll_count1
from out_ta_book t
where t.sjmxlh is not null and trunc(:new.dcfrq) - trunc( dghsj ) <= 90
and t.sbrlsh = ls_sbrlsh;
if ll_count1 is null then ll_count1 := 0 ;end if;
if ll_count1 <= 0 then
update out_Ta_book t
set t.sjmxlh = to_char(sysdate,‘yyyy’)||to_char( out_jmxlh.nextval,‘fm00000000’ )
where t.smzhm in ( select smzhm from out_ta_presc_m_t tm where tm.scfh = :new.scfh)
and t.sbrlsh = ls_sbrlsh ;
else
select t.sjmxlh into ls_jmxlh
from out_ta_book t
where t.sjmxlh is not null and sbrlsh = ls_sbrlsh and trunc(:new.dcfrq) - trunc( dghsj ) <= 90
and rownum = 1
order by t.dghsj desc;
update out_Ta_book t
set t.sjmxlh = ls_jmxlh
where t.smzhm in ( select smzhm from out_ta_presc_m_t tm where tm.scfh = :new.scfh)
and t.sbrlsh = ls_sbrlsh ;
end if;
end if;
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值