6.1. Introduction

A trigger is a compiled procedure stored in the database. The language you use is PL/SQL. You code and compile a trigger in the same manner you code stored procedures. The following is the SQL*Plus session that creates and demonstrates a simple Insert Row trigger. This trigger calls DBMS_OUTPUT to print “executing temp_air” for each row inserted.

 SQL> set feedback off SQL> CREATE TABLE temp (N NUMBER); SQL> CREATE OR REPLACE TRIGGER temp_air 2 AFTER INSERT ON TEMP 3 FOR EACH ROW 4 BEGIN 5 dbms_output.put_line('executing temp_air'); 6 END; 7 / 8 SQL> INSERT INTO temp VALUES (1); -- insert 1 row executing temp_air SQL> INSERT INTO temp SELECT * FROM temp; -- insert 1 row executing temp_air SQL> INSERT INTO temp SELECT * FROM ...

Get Programming Oracle® Triggers and Stored Procedures, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.