query

Tags:
Oracle
how to write a trigger in oracle

Answer Wiki

Thanks. We'll let you know when a new response is added.

Here’s a sample audit trigger which you can modify for your needs.

CREATE OR REPLACE TRIGGER tableaudiu
AFTER INSERT OR UPDATE
ON tablename
REFERENCING NEW as new
FOR EACH ROW
DECLARE
v_aud_tp tablenameaud.audit_type%type;
v_aud_id tablenameaud.last_modified_name%type;
v_aud_dt tablenameaud.last_modified_date%type;
BEGIN
v_aud_id := USER;
v_aud_dt := SYSDATE;
IF inserting THEN
v_aud_tp := ‘I’;
ELSE
v_aud_tp := ‘U’;
END IF;
INSERT INTO tablenameaud (
ID,
COMMENTS,
ACTIVE_IND,
STATUS_TOOL_TIP_ID,
LAST_MODIFIED_NAME,
LAST_MODIFIED_DATE,
AUDIT_TYPE)
VALUES (
:new.id,
:new.comments,
:new.active_ind,
:new.status_tool_tip_id,
v_aud_id,
v_aud_dt,
v_aud_tp);
END;
/

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following