Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: Trigger sample Jump to:  
Category: >> Oracle PL/SQL >> Trigger sample Bookmark and Share

<< lastnext >>

Snippet Name: Trigger sample

Description: Basic code for creating triggers.

Also see:
» TRIGGER Example
» Create trigger in Oracle

Comment: There are six kinds of triggers, BEFORE and AFTER of INSERT, UPDATE, and DELETE.

Language:
Highlight Mode: PLSQL
Last Modified: March 02nd, 2009

-- File: account_trigs.sql
-- By:   Craig Battis
-- Modified by: Martin White
-- Date: 02-nov-95
--
-- Purpose: To create triggers for creating account balance and account charge
--          date records.  
--
-- Sccs Info:
-- Program: account_trigs.sql
-- Version: 1.4
-- Date:    95/11/14 14:05:27
-- Path:    /u01/home/ribs/sccs/s.account_trigs.sql
-- Whatout: @(#)account_trigs.sql     1.4   95/11/14
--
 
CREATE OR REPLACE TRIGGER trig_rb_accounts
after INSERT OR UPDATE OR DELETE ON snap$_rb_accounts
FOR each ROW
BEGIN
  IF     inserting THEN 
    INSERT INTO rb_account_balances
        (
        ACCOUNT_ID                      ,
     PREVIOUS_BALANCE
        )
        VALUES
        (
        :NEW.ACCOUNT_ID                 ,
        0.0
        );
  ELSIF  updating  THEN NULL;
  ELSIF  deleting  THEN NULL;
END IF;
END;
/
 
CREATE OR REPLACE TRIGGER trig_rb_account_charges
after INSERT OR UPDATE OR DELETE ON snap$_rb_account_charges
FOR each ROW
BEGIN
  IF     inserting THEN 
    INSERT INTO RB_ACCOUNT_CHARGES_DATES
      (
          ACCOUNT_CHARGE_ID
      )
    VALUES
      (
          :NEW.ACCOUNT_CHARGE_ID
      );
  ELSIF  updating  THEN NULL;
  ELSIF  deleting  THEN NULL;
END IF;
END;
/
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 61 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?