Call (800) 766-1884 for Oracle support & training
Free Oracle Tips


Oracle Consulting Support
Oracle Upgrades
Use New Oracle Features
Oracle Replication Support
Oracle Training
Remote Oracle DBA
System Documentation
Oracle Tips
Oracle Performance
 

Free Oracle Tips


 

HTML Text

BC Oracle tuning

Oracle training

Oracle support

Remote Oracle

 

 

   
 

WHEN Clause
Oracle Tips by Burleson
 

The WHEN clause is a Boolean expression that is evaluated by Oracle before the trigger’s body is executed. Using the WHEN clause allows a developer to improve performance by testing simple conditions before the trigger’s body is executed. Listing 7.15 illustrates the use of the WHEN clause.

Listing 7.15 Using the WHEN clause.

CREATE OR REPLACE
TRIGGER CLASSES_ARU
AFTER UPDATE
ON CLASSES
FOR EACH ROW
WHEN new.course_number != old.course_number
 
DECLARE
   xLOCATION_CONFLICT   EXCEPTION;
 
BEGIN
   SELECT 1
   INTO   nClassConflicts
   FROM   CLASSES
   WHERE  course_number   = :new.course_number
   AND    course_location = :new.course_location
   AND    course_time     = :new.course_time;
 
   RAISE xLOCATION_CONFLICT;
 
EXCEPTION
   WHEN NO_DATA_FOUND THEN
        NULL;
END CLASSES_ARU;
/

Trigger Body

The body of a database trigger, with the restrictions that we’ve already discussed, is a standard block of PL/SQL. The body of a trigger is highlighted in Listing 7.16.

Listing 7.16 A trigger body.

CREATE OR REPLACE
TRIGGER CLASSES_ARU
AFTER UPDATE
ON CLASSES
FOR EACH ROW
WHEN new.course_number != old.course_number
 
DECLARE
    xLOCATION_CONFLICT   EXCEPTION;
 
 BEGIN
    SELECT 1
    INTO   nClassConflicts
    FROM   CLASSES
    WHERE  course_number   = :new.course_number
    AND    course_location = :new.course_location
    AND    course_time     = :new.course_time;
 
    RAISE xLOCATION_CONFLICT;
 
 EXCEPTION
    WHEN NO_DATA_FOUND THEN
         NULL;
 END CLASSES_ARU;
/ 

               
This is an excerpt from the book "High Performance Oracle Database Automation" by Jonathan Ingram and Donald K. Burleson, Series Editor.

  
 

Oracle performance tuning software 
 
 
 
 

Oracle performance tuning book

 

 
 
 
Oracle performance Tuning 10g reference poster
 
 
 
Oracle training in Linux commands
 
Oracle training Excel
 
Oracle training & performance tuning books
 

 

   

Copyright © 1996 -  2014 by Burleson. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation. 

Hit Counter