Tuesday, 12 July 2011

Oracle Trigger

// Below trigger insert record in  bps_company_h when any insert or update operation perform in //bps_company

CREATE OR REPLACE TRIGGER trg_insupd_bps_company
   AFTER INSERT OR UPDATE
   ON bps_company
   REFERENCING NEW AS NEW OLD AS OLD
   FOR EACH ROW
DECLARE
   v_err_msg   VARCHAR2 (1024);
BEGIN
   INSERT INTO bps_company_h
               (company_id, company_code, company_name,
                is_enabled, consumer_no_min_length,
                consumer_no_max_length, min_bill_amount,
                max_bill_amount, bill_type_id,
                consumer_no_dt_id, grace_time,
                allowed_days_after_due_date, provider1_id,
                provider2_id, provider3_id, barcode_length,
                barcode_format, created_by, created_date,
                updated_by, updated_date, allow_bulk_billing,
                is_reversal_applicable, surcharge_type_id,
                surcharge_value, surcharge_min_value,
                surcharge_max_value, bill_marking_required,
                sms_recipient, email_recipient, long_name,
                sub_category_id, display_fields,IS_REMAINING_AMOUNT_AVAILABLE
               )
        VALUES (:NEW.company_id, :NEW.company_code, :NEW.company_name,
                :NEW.is_enabled, :NEW.consumer_no_min_length,
                :NEW.consumer_no_max_length, :NEW.min_bill_amount,
                :NEW.max_bill_amount, :NEW.bill_type_id,
                :NEW.consumer_no_dt_id, :NEW.grace_time,
                :NEW.allowed_days_after_due_date, :NEW.provider1_id,
                :NEW.provider2_id, :NEW.provider3_id, :NEW.barcode_length,
                :NEW.barcode_format, :NEW.created_by, :NEW.created_date,
                :NEW.updated_by, :NEW.updated_date, :NEW.allow_bulk_billing,
                :NEW.is_reversal_applicable, :NEW.surcharge_type_id,
                :NEW.surcharge_value, :NEW.surcharge_min_value,
                :NEW.surcharge_max_value, :NEW.bill_marking_required,
                :NEW.sms_recipient, :NEW.email_recipient, :NEW.long_name,
                :NEW.sub_category_id, :NEW.display_fields,:NEW.IS_REMAINING_AMOUNT_AVAILABLE
               );
EXCEPTION
   WHEN OTHERS
   THEN
      v_err_msg := SQLERRM;
END;

No comments:

Post a Comment