Am very new to Oracle triggers. Suppose I have a trigger on an insert in the table emp. Is there a way to find out what was the inserted record that fired the trigger. I wanted the trigger to have code that does something if the inserted record was a particular value.
A trigger will fire if it is enabled, and not fire if it is not. You can check the status from any of the xxx_TRIGGERS views.
The CREATE TRIGGER statement is used to add triggers to the database schema. Triggers are database operations that are automatically performed when a specified database event occurs. Each trigger must specify that it will fire for one of the following operations: DELETE, INSERT, UPDATE.
Input : SELECT TRIGGER_NAME FROM USER_TRIGGERS; Output : Input : SELECT * FROM USER_TRIGGERS; Output : NOTE: Using * means that we need all the attributes for that database object or Trigger to get displayed.
The procedure RAISE_APPLICATION_ERROR lets you issue user-defined ORA- error messages from stored subprograms. That way, you can report errors to your application and avoid returning unhandled exceptions.
Assuming you have a row-level trigger, you can simply use the :NEW
pseudo-record
CREATE TRIGGER name_of_trigger
BEFORE INSERT ON emp
FOR EACH ROW
DECLARE
<<declare variables>>
BEGIN
IF( :new.ename = 'JUSTIN' )
THEN
<<do something if the newly inserted ENAME value is 'JUSTIN'>>
END IF;
END;
For a DDL trigger, the approach is completely different. In that case, the pseudofunctions ora_dict_obj_owner and ora_dict_obj_name will return the owner and name of the table that the DDL statement is operating on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With