`

trigger

阅读更多

create or replace TRIGGER tiuda_t_car
BEFORE INSERT OR UPDATE OF v_plate_number,v_car_number,v_car_tel,n_userid or delete ON T_CAR 
FOR EACH ROW
/*******************************************************
**  程序类别 : TRIGGER            

**  说明:通过trigger实现数据的更新与插入                     
*******************************************************/
DECLARE
  
  
  
BEGIN
   
--     IF updating  THEN  
--       -- IF nvl(:new.c_isdel,'N')='Y' THEN
--       
--        MERGE INTO center_carinfo a
--        USING(SELECT n_user_id,v_user_email,v_username,v_name,v_nativeplace ,v_tel FROM t_user WHERE n_user_id=:NEW.n_userid) b 
--           ON (a.vehicle_no=:old.v_plate_number)
--           when matched then
--              update
--                 set a.driver_name=b.v_name,
--                     a.tel=b.v_tel,
--                     a.v_carnumber=:new.v_car_number
--            when not matched then
--               insert ( vehicle_no,driver_name,tel,v_carnumber)
--               values(:new.v_plate_number,b.v_name, b.v_tel,:new.v_car_number);
--     end if;   
--
--N_USER_ID, V_USERNAME, V_USER_PWD, V_NAME, C_SEX, V_TEL, V_NATIVEPLACE, V_USER_EMAIL, C_ISADMIN, V_HEAD_IMAGE,
--                   V_DRIVER_ID, V_LICENCE, V_ORG_NAME, D_REG_TIME, V_NAME_ONE, V_NAME_TWO, V_MOBILE_ONE, V_MOBILE_TWO,
--                   V_ADDRESS_ONE, V_ADDRESS_TWO, C_ISDEL, D_DELTIME
    
     IF inserting OR UPDATING THEN
        MERGE INTO center_carinfo a
        USING(SELECT n_user_id,v_user_email,v_name,v_nativeplace ,v_tel,v_driver_id,v_licence,
                     v_org_name,d_reg_time,v_name_one,v_name_two,v_mobile_one,v_mobile_two,v_address_one,v_address_two
                FROM t_user WHERE n_user_id=:NEW.n_userid) b 
           ON (a.vehicle_no=:NEW.v_plate_number)
           when matched then
              update
                 set a.driver_name=b.v_name,
                    a.driver_id=b.v_driver_id,
                    a.licence=b.v_licence,
                    a.org_name=b.v_org_name,
                    a.tel=:NEW.v_car_tel,
                    a.v_carnumber=:new.v_car_number,
                    a.reg_time=b.d_reg_time,
                    a.name_one=b.v_name_one,
                    a.name_two=b.v_name_two,
                    a.mobile_one=b.v_mobile_one,
                    a.mobile_two=b.v_mobile_two,
                    a.address_one=b.v_address_one,
                    a.address_tweo=b.v_address_two
            when not matched then
               insert ( vehicle_no,driver_name,driver_id,licence,a.org_name,tel,v_carnumber,a.reg_time,
                        a.name_one,a.name_two,a.mobile_one,a.mobile_two,a.address_one,a.address_tweo)
               values(:new.v_plate_number,b.v_name,b.v_driver_id,b.v_licence,b.v_org_name,:NEW.v_car_tel,
                      :new.v_car_number,b.d_reg_time,b.v_name_one,b.v_name_two,b.v_mobile_one,b.v_mobile_two,b.v_address_one,b.v_address_two);
     end if;
    
      if deleting then
         raise_application_error(-20008,'此资料不允许删除!');
     end if;            
        null;
END tiuda_t_car;

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics