Advertisement
psi_mmobile

NEW on_set_person_inactive TRIGGER

Sep 14th, 2022
1,314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.72 KB | None | 0 0
  1. CREATE OR REPLACE TRIGGER on_set_person_inactive
  2. after UPDATE OF person_status_id ON person
  3. FOR each ROW
  4. DECLARE
  5.     v_timezone operation_center.timezone%TYPE;
  6.     v_date_day DATE;
  7.     v_vehicle_owner_id NUMBER(10); -- only for Sixco for now
  8.     v_gui_user_id NUMBER(10);
  9.     v_temp_loginname VARCHAR(20);
  10. BEGIN
  11.     IF :old.person_status_id = 0 AND :NEW.person_status_id IN (1,2) THEN
  12.    
  13.         SELECT oc.timezone, vo.vehicle_owner_id
  14.         INTO v_timezone, v_vehicle_owner_id
  15.         FROM operation_center oc, vo_person_category vpc, vehicle_owner vo
  16.         WHERE vpc.vo_person_category_id = :NEW.vo_person_category_id
  17.         AND vo.vehicle_owner_id = vpc.vehicle_owner_id
  18.         AND oc.operation_center_id = vo.default_operation_center_id;
  19.        
  20.         SELECT gu.gui_user_id
  21.         INTO v_gui_user_id
  22.         FROM gui_users gu
  23.         WHERE gu.profiled_person_id = :old.person_id;
  24.        
  25.         IF v_gui_user_id IS NOT NULL THEN
  26.        
  27.             SELECT DBMS_RANDOM.string('X', 20)
  28.             INTO v_temp_loginname
  29.             FROM dual;
  30.            
  31.             UPDATE gui_users
  32.             SET is_active='N',
  33.             loginname = v_temp_loginname
  34.             WHERE gui_user_id = v_gui_user_id;
  35.         END IF;
  36.        
  37.         IF v_vehicle_owner_id = 101408 THEN
  38.        
  39.             v_date_day := TRUNC(touserdate(sysdateutc, v_timezone));
  40.            
  41.             DELETE FROM pd_day
  42.             WHERE person_id = :NEW.person_id
  43.             AND date_day >= v_date_day + 1;
  44.            
  45.             DELETE FROM pd_trf_day
  46.             WHERE person_id = :NEW.person_id
  47.             AND date_day >= v_date_day + 1;
  48.         END IF;
  49.     END IF;
  50.   EXCEPTION WHEN OTHERS THEN
  51.   NULL;
  52. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement