Oracle更新后触发批量更新

时间:2015-08-11 09:32:43

标签: oracle

有没有办法在更新触发器之后对oracle进行编程,以便在执行批量更新时仅在历史记录表中插入最新记录。

1 个答案:

答案 0 :(得分:1)

假设您省略for each row子句。比你可以实现一个语句触发器,只有在一个事务提交后触发。软件可能是这样的:

create or replace trigger ai_test
after insert on orders

declare

my_test_row orders%rowtype;

begin


select o.*
into my_test_row
from orders o
where o.order_date = (select max(order_date) -- must be the identifying attribute 
                      from orders);


insert into orders_his (id, cust_id, prod_id, order_date) 
values  
( my_test_row.id
, my_test_row.cust_id
, my_test_row.prod_id
, my_test_row.order_date);             


end;