当前位置: 首页 > 数据库 > Oracle教程 > 正文

oracle触发器实例

时间:2017-03-31
//新增字段更改值

create or replace trigger trg_insert_terminal_addr_hex
before insert
on r_tmnl_run
for each row
begin
:new.terminal_addr_hex:=substr(:new.terminal_addr,1,4)|| lpad(trim(to_hex(substr(:new.terminal_addr,5,5))),4,'0') ;
END;
//修改字段赋值
CREATE OR REPLACE TRIGGER trg_update_terminal_addr_hex
BEFORE   UPDATE
  ON r_tmnl_run
  FOR EACH ROW
DECLARE
  BEGIN
if(:old.TERMINAL_ID=:new.TERMINAL_ID)then
:new.terminal_addr_hex:=substr(:new.terminal_addr,1,4)|| lpad(trim(to_hex(substr(:new.terminal_addr,5,5))),4,'0') ;
end if;
END;

来源:http://mengjichen.iteye.com/blog/2366514