Oracle使用触发器实例

eg1:

create or replace trigger SYM_U_BS_STUDENT after update on BASE_STUDENT for each row
begin
      if (:new.EVENT_SOURCE=0) or (:new.EVENT_SOURCE is null)  then
           insert into sym_STUDENT (event_type,sym_id,id,school_id,class_id,student_name,old_name,student_code,unitive_code,identity_card,sex,birthday,mobile_phone,is_leave_school,enroll_year,class_inner_code,economy_state,card_number,is_singleton,stayin,boorish,is_local_source,student_recruitment,study_mode,native_place,homepage,email,link_phone,link_address,postalcode,region_code,creation_time,modify_time,is_deleted,event_source,is_freshman,password,now_state,school_district,meetexam_code,source_place,is_specialid,dir_id,file_path,health,nation,background,polity_join_date,home_address,to_school_date,dorm,dorm_tel,spec_id,specpoint_id,enter_score)
                   values(decode(:new.is_deleted,1,'D',0,'U'),sys_guid(),:new.id,:new.school_id,:new.class_id,:new.student_name,
       :new.old_name,:new.student_code,:new.unitive_code,:new.identity_card,:new.sex,:new.birthday,:new.mobile_phone,
       :new.is_leave_school,:new.enroll_year,:new.class_inner_code,:new.economy_state,:new.card_number,:new.is_singleton,:new.stayin,:new.boorish,:new.is_local_source,:new.student_recruitment,:new.study_mode,:new.native_place,
       :new.homepage,:new.email,:new.link_phone,:new.link_address,:new.postalcode,:new.region_code,:new.creation_time,
       :new.modify_time,:new.is_deleted,:new.event_source,:new.is_freshman,:new.password,:new.now_state,
       :new.school_district,:new.meetexam_code,:new.source_place,:new.is_specialid,:new.dir_id,:new.file_path,
       :new.health,:new.nation,:new.background,:new.polity_join_date,:new.home_address,:new.to_school_date,:new.dorm,:new.dorm_tel,:new.spec_id,:new.specpoint_id,:new.enter_score);
       end if;
end;

 

eg2:

create or replace trigger tr_u_student after update on base_student  for each row
begin
 if(:new.student_name <> :old.student_name  or :new.sex <> :old.sex or :old.sex is null
 or :new.class_id <> :old.class_id or :old.class_id is null or :new.mobile_phone <> :old.mobile_phone
  or :old.mobile_phone is null
 or :new.birthday <> :old.birthday or :old.birthday is null or :new.school_id <> :old.school_id ) then
   update base_user set real_name=:new.student_name,sex=:new.sex,class_id=:new.class_id,
    mobile_phone=:new.mobile_phone,birthday=:new.birthday,unit_id=:new.school_id,event_source=0,
    modify_time=sysdate  where owner_id=:new.id;
 end if;
end;

eg3:

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值