We Recommend

SQL Cookbook SQL Cookbook
Written in O'Reilly's popular Problem/Solution/Discussion style, the SQL Cookbook is sure to please. Anthony's credo is: "When it comes down to it, we all go to work, we all have bills to pay, and we all want to go home at a reasonable time and enjoy what's still available of our days." The SQL Cookbook moves quickly from problem to solution, saving you time each step of the way.


Posted By

indianocean on 05/05/08


Tagged

sql Oracle PLSQL sp


Versions (?)


Simple Oracle Trigger


Published in: SQL 


  1. CREATE OR REPLACE
  2. TRIGGER T_INSERT_REGION
  3. AFTER INSERT ON LOCATION
  4. FOR EACH ROW
  5. DECLARE
  6. new_region varchar2(200);
  7. has_region number;
  8. BEGIN
  9. new_region := :new.region;
  10.  
  11. SELECT count(*) INTO has_region FROM lu_region WHERE region = new_region;
  12.  
  13. IF (has_region = 0) then
  14. INSERT INTO lu_region (region) VALUES (new_region);
  15. end IF;
  16. END;

Report this snippet 

You need to login to post a comment.