oracle 触发器:条件判断自动执行某些任务,不仅仅用于自增id
2015-01-23 11:29
274 查看
实现功能:当某张表写入数据时,同时将处理后的数据写入另一张表
create or replace trigger TG_sale_warehousein_gh after
insert ON t_sale_warehousein FOR EACH ROW
declare yes number;
begin
select count(*) into yes from t_sale_warehousein2 t5 where t5.product_code=:NEW.product_code and to_char(t5.warehousein_confirm_date,'yyyy-mm-dd')=to_char(:NEW.warehousein_confirm_date,'yyyy-mm-dd');
if(yes>0) then
update t_sale_warehousein2 set
--product_code=:NEW.product_code,
--product_name=:NEW.product_name,
--plate_code=:NEW.plate_code,
--grade=:NEW.grade,
warehousein_num=warehousein_num+:NEW.warehousein_num,
warehousein_weight=warehousein_weight+:NEW.warehousein_weight
--warehousein_confirm_date=:NEW.warehousein_confirm_date
where product_code=:NEW.product_code and to_char(warehousein_confirm_date,'yyyy-mm-dd')=to_char(:NEW.warehousein_confirm_date,'yyyy-mm-dd');
end if;
if(yes=0) then
insert into t_sale_warehousein2(product_code,product_name,plate_code,grade,warehousein_num,warehousein_weight,warehousein_confirm_date)
values(:NEW.product_code,:NEW.product_name,:NEW.plate_code,:NEW.grade,:NEW.warehousein_num,:NEW.warehousein_weight,:NEW.warehousein_confirm_date);
end if;
end;
create or replace trigger TG_sale_warehousein_gh after
insert ON t_sale_warehousein FOR EACH ROW
declare yes number;
begin
select count(*) into yes from t_sale_warehousein2 t5 where t5.product_code=:NEW.product_code and to_char(t5.warehousein_confirm_date,'yyyy-mm-dd')=to_char(:NEW.warehousein_confirm_date,'yyyy-mm-dd');
if(yes>0) then
update t_sale_warehousein2 set
--product_code=:NEW.product_code,
--product_name=:NEW.product_name,
--plate_code=:NEW.plate_code,
--grade=:NEW.grade,
warehousein_num=warehousein_num+:NEW.warehousein_num,
warehousein_weight=warehousein_weight+:NEW.warehousein_weight
--warehousein_confirm_date=:NEW.warehousein_confirm_date
where product_code=:NEW.product_code and to_char(warehousein_confirm_date,'yyyy-mm-dd')=to_char(:NEW.warehousein_confirm_date,'yyyy-mm-dd');
end if;
if(yes=0) then
insert into t_sale_warehousein2(product_code,product_name,plate_code,grade,warehousein_num,warehousein_weight,warehousein_confirm_date)
values(:NEW.product_code,:NEW.product_name,:NEW.plate_code,:NEW.grade,:NEW.warehousein_num,:NEW.warehousein_weight,:NEW.warehousein_confirm_date);
end if;
end;
相关文章推荐
- Python While循环语句 Python 编程中 while 语句用于循环执行程序,即在某条件下,循环执行某段程序,以处理需要重复处理的相同任务。其基本形式为: while 判断条件:
- Oracle DB 使用调度程序自动执行任务
- ORACLE 中,数据的id号自动生成,利用触发器的实现
- Oracle主键ID设置自动增长(序列+触发器)
- Oracle DB 使用调度程序自动执行任务
- oracle建表id自动增长及触发器无效解答
- oracle主键自动增长的实现 Oracle Sequence oracle maxid自动生成--ORA-00001: 违反唯一约束条件 (NAME.SYS_C005547)产生的原因之一(select * from all_cons_columns w
- Oracle主键ID设置自动增长(序列+触发器)
- Oracle计划任务JOB不自动执行的问题
- Linux下的crontab定时、执行任务命令详解 oracle 自动备份
- 利用windows任务执行批处理,实现ORACLE自动备份、删除过早备份
- Oracle主键ID设置自动增长(序列+触发器)
- oracle 序列 + 触发器 实现 ID自动增长
- oracle 10 job任务不自动执行,解决办法
- FTP导入脚本自动执行任务示例
- hibernate映射oracle自动增长ID
- FTP导入脚本自动执行任务示例
- FTP导入脚本自动执行任务示例
- FTP导入脚本自动执行任务示例
- 在weblogic中设置启动时自动定时执行的任务(转)