Re: Trigger Question
From: Jeff Hunter <jeffh_at_btitelecom.net>
Date: Mon, 13 Sep 1999 13:00:42 -0400
Message-ID: <37dd2df2_at_defiant.btitelecom.net>
>
>In using triggers - I am doing an insert into a separate table based on an
>update or insert into a table. Is there a way to get the Oracle user ID of
>the person performing the update from within the trigger to use in the
>insert statment?
>
>
>Michael Milliron
>mikem_at_msamail.com
>okana_at_msn.com
>
>
>
> Received on Mon Sep 13 1999 - 19:00:42 CEST
Date: Mon, 13 Sep 1999 13:00:42 -0400
Message-ID: <37dd2df2_at_defiant.btitelecom.net>
No question is a stupid question.
You can use the "user" keyword in your trigger PL/SQL block to
return the current user. Although triggers run as the owner of the object,
the user will return the user who is causing the trigger to fire...
SQL> select user, sysdate from
dual;
USER
SYSDATE
------------------------------ ---------
SYSTEM 13-SEP-99
------------------------------ ---------
SYSTEM 13-SEP-99
In a trigger it would look like:
CREATE OR REPLACE TRIGGER ANI_AUDIT
AFTER INSERT OR UPDATE OR DELETE ON ANI
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
AFTER INSERT OR UPDATE OR DELETE ON ANI
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
IF INSERTING THEN
INSERT INTO ANI_AUDIT (user_id, audit_ts, action_cd, id, ani)
VALUES (user,sysdate,'INSERT',:new.id, :new.ani);
IF INSERTING THEN
INSERT INTO ANI_AUDIT (user_id, audit_ts, action_cd, id, ani)
VALUES (user,sysdate,'INSERT',:new.id, :new.ani);
END IF;
END;
END;
Michael Milliron <~okana_at_msn.com>
wrote in message
...
>This may be a stupid question:>
>In using triggers - I am doing an insert into a separate table based on an
>update or insert into a table. Is there a way to get the Oracle user ID of
>the person performing the update from within the trigger to use in the
>insert statment?
>
>
>Michael Milliron
>mikem_at_msamail.com
>okana_at_msn.com
>
>
>
> Received on Mon Sep 13 1999 - 19:00:42 CEST