fatima mohamed
fatima mohamed

Reputation: 3

trying to use trigger

I'm trying to activate a trigger when a new employee is added. the trigger should store the username of the person that has done the insert and the time it happened. Using Oracle database.

So far my code for the trigger is:

CREATE OR REPLACE TRIGGER insert_2    
AFTER INSERT ON employees
for each row    
DECLARE
    vUser varchar(50);
begin

    select user into vUser from dual;

    insert into audit_cheker1 (date_create, inserted_by) 
    values (sysdate(), vUser);

END;
/

The trigger works but after I try to insert a new record it doesn't work and tells me error in the trigger.

enter image description here

Upvotes: 0

Views: 30

Answers (1)

APC
APC

Reputation: 146239

The error message is telling you your trigger is invalid, that is it contains syntax errors and cannot be compiled. So you need to fix the compilation errors.

There are several ways to find errors. You can run a query:

select * from user_errors
where type = 'TRIGGER'
and name = 'INSERT_2'
/

You could use the SQL*Plus command show errors after the CREATE TRIGGER statement.

Or, as it seems you're using SQL Developer, you could open the trigger in the Object Navigator. You'll see the tab has several panes, one of which is labelled Errors. Open that pane to see what's wrong.

Here is one for free: although sysdate is technically a function it is a special one. It never takes any parameters and calling it with brackets is wrong. Remove these brackets: sysdate().

Upvotes: 1

Related Questions