


--------------------------------------------------------------------------
--Trigger Name: C1_BI_D_CETD (Generated Code)
--Date: 04-07-2011 17:38:25
--------------------------------------------------------------------------

CREATE OR REPLACE TRIGGER C1_BI_D_CETD
   AFTER UPDATE
   ON CI_COLL_EVT_TYP_L
   FOR EACH ROW

DECLARE

   ws_proc_name     VARCHAR2(30) := 'C1_BI_D_CETD';
   ws_label         VARCHAR2(200);
   ws_batch_cd      ci_batch_ctrl.batch_cd%TYPE := 'EXTCET';
   ws_batch_nbr     ci_batch_ctrl.next_batch_nbr%TYPE;
   ws_action_ind    CHAR(1) := NULL;
   ws_chg_log_id    CHAR(14) := NULL;

BEGIN

   ws_label := 'Fetching batch_nbr from ci_batch_ctrl';
   SELECT next_batch_nbr
     INTO ws_batch_nbr
     FROM ci_batch_ctrl
    WHERE batch_cd = ws_batch_cd;

   ws_label := 'Setting update action flag';
   IF UPDATING THEN

      IF ((:NEW.DESCR <> :OLD.DESCR)) THEN
         ws_action_ind := 'U';

      END IF;

   END IF;

   IF ws_action_ind IN ('I','U') THEN

      LOOP
         ws_chg_log_id := TO_NUMBER(ROUND(DBMS_RANDOM.VALUE(1,99999999999999),0));

         BEGIN

            ws_label := 'Populating change log table for insert/update action';
            INSERT INTO ci_chg_log (
               chg_log_id
               ,batch_cd
               ,batch_nbr
               ,chg_dttm
               ,chg_type_flg
               ,tbl_name
               ,pk_val1
            ) VALUES (
               ws_chg_log_id
               ,ws_batch_cd
               ,ws_batch_nbr
               ,SYSDATE
               ,ws_action_ind
               ,'CI_COLL_EVT_TYP_L'
               ,:NEW.COLL_EVT_TYP_CD
            );

            EXIT;

         EXCEPTION
            WHEN DUP_VAL_ON_INDEX THEN
               NULL;

         END;

      END LOOP;

   END IF;

EXCEPTION
   WHEN OTHERS THEN
      RAISE_APPLICATION_ERROR(-20001,'Database Error ' || SQLCODE || ' occured while ' || ws_label || ' in ' || ws_proc_name);

END;
/