Auditing inside a Trigger

Inside my trigger I want to write for auditing purposes certain values that get updated. However I am unable to commit within my trigger. Is there some way to write certain values to another table when my trigger is fired?

Yes you can do insert, update and delete operation on other tables inside a trigger. But COMMIT is not allowed inside a trigger.
Because a trigger is considered as a part of a transaction. So the action of a trigger should not get commit unless the invoking statement is committed.
But even then you can define a trigger as a [AUTONOMOUS_TRANSACTION.|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/autonotransaction_pragma.htm#LNPLS01302] Which lets you to commit. But you must be very careful before using it. Know the effects of using it before doing so.

Similar Messages

  • Which is better database audit or database trigger ?

    Hello ,
    Hope everyone is doing well.............
    I have a doubt , which i have mentioned below ........ Plz help me on this ....
    Suppose I want to track all the actions that is going to be performed on a table (example -UPDATE), like
    1-> which user has modified the table .
    2-> At which time the data has been modified .
    3 -> before image of data and after image of the data
    In order to track all the above information , we can user oracle database audit or we can create a trigger that wiill fire for that
    perticular event and track all the informations in to a table .
    But my questions are
    -> On which scenario should i use trigger
    -> On which scenario should i use database audit
    -> In between trigger and database audit , which one sholud be used keeping in mind about the performance .
    Thanks

    user9085814 wrote:
    Hello ,
    Hope everyone is doing well.............
    I have a doubt , which i have mentioned below ........ Plz help me on this ....
    Suppose I want to track all the actions that is going to be performed on a table (example -UPDATE), like
    1-> which user has modified the table .
    2-> At which time the data has been modified .
    3 -> before image of data and after image of the data
    In order to track all the above information , we can user oracle database audit or we can create a trigger that wiill fire for that
    perticular event and track all the informations in to a table .
    But my questions are
    -> On which scenario should i use trigger
    -> On which scenario should i use database audit
    -> In between trigger and database audit , which one sholud be used keeping in mind about the performance .
    ThanksUse database auditing whenever possible, FGA is also available on DML from 10g onwards.Use trigger when you've to capture before and after value.
    http://dbpedias.com/wiki/Oracle:Fine_Grained_Auditing_vs_Triggers
    http://www.oracle.com/technetwork/articles/sql/week10-10gdba-097438.html

  • Function inside a trigger

    Can i write function inside a trigger?
    My requirement is that i've to call a function inside a trigger. Since this function is not frequently used so what i am thinking that i should write this function inside trigger. Can i do that?
    i know that function can be called inside trigger, but can i create a function inside trigger?
    if yes, then how?
    give me an overview. I'll appricate any kind of help.

    Hi,
    jadoo wrote:
    you mean to say that i can create a function in declaration section of trigger?Just an example,
    SQL> select empno,sal, deptno
      2  from emp
      3  where empno=7369;
         EMPNO        SAL     DEPTNO
          7369        800         20
    SQL> create table sal_inc_tab
      2  (inc_empno number,
      3  inc_sal number);
    Table created.
    SQL> create or replace trigger f_trg After update on emp
      2  REFERENCING NEW AS NEW OLD AS OLD
      3  FOR EACH ROW
      4  Declare
      5   v_inc_sal number;
      6   function sal_inc (v_sal number)
      7   return number as
      8   Begin
      9    return :new.sal+3000;
    10   end sal_inc;
    11  BEGIN
    12   v_inc_sal:=sal_inc(:new.sal);
    13   Insert into sal_inc_tab values(:new.empno,v_inc_sal);
    14  end;
    15  /
    Trigger created.
    SQL> select * from sal_inc_tab;
    no rows selected
    SQL> update emp
      2  set deptno=10
      3  where empno=7369;
    1 row updated.
    SQL> select * from sal_inc_tab;
    INC_EMPNO    INC_SAL
          7369       3800You can do same thing without function. Here there was no specific logic as such, it was just to show you how this is executed.
    Twinkle

  • Event Logs for Audit inside SSMS

    I've been asked to create some audit function inside SS for my dept.  So currently I have added audit specs on both the server and database level.  To keep it simple for my first time around, I created one Audit Action Type (on the database level)
    for a Select statement, Obj Class=Object, Object=dbo, Object Name = table1, Principal=public. 
    Then I ran a select statement (select top 100 * from table1). 
    I am not privy to logging into the server (based on security reasons).  The setup of audit was done from my local SSMS application connected to the server.  Is it possible to view this audit inside my local SSMS (ver 2012)? 
    Regards,
    Brian

    you can use TSQL to get the information.. you need to know you audit log file path and name...
    you can find that in under security -- Audits --Right click and properties and you can replace that
    with the path and find the current file replace that as well.
    you can filter to the database_name and if you want more specific, you can add more fliter conditions
    select * from fn_get_audit_file('<<auditfilepath>>\ServerAudit_6DAE56DE-E508-4A47-A2FF-FE737A285E84_0_130728921550980000.sqlaudit',default,default)
    where database_name='Yourdatabase'
    Hope it Helps!!

  • Call *.jar inside the trigger (MS SQL)

    Hi!
    I'm just looking around google and can't find any good news.. The problem is: how to call *.jar inside the trigger. Trigger is stored in M$ Server.
    Tnx, if any response! ;)

    What?

  • Sequence inside a Trigger ??

    Is it possible to use a sequence inside trigger's definition ?
    I don't understand why when i give a static value to my RowId in a trigger's definition it works, but when get a value from a sequence, the trigger become invalid.
    Please Help.

    Somewhat off the spatial topic but what the heck! This is easy :
    SQL> create table t
    2 (person_id number,
    3 person_name varchar2(32));
    Table created.
    SQL> create sequence person_id_seq start with 1 increment by 1;
    Sequence created.
    SQL> create trigger person_id_trig
    2 before insert
    3 on t
    4 for each row
    5 begin
    6 select person_id_seq.nextval
    7 into :new.person_id
    8 from dual;
    9 end;
    10 /
    Trigger created.
    SQL> insert into t (person_name) values ('Steve');
    1 row created.
    halls@GENDEV> select * from t;
    PERSON_ID PERSON_NAME
    1 Steve
    SQL> insert into t (person_name) values ('Rod');
    1 row created.
    halls@GENDEV> select * from t;
    PERSON_ID PERSON_NAME
    1 Steve
    2 Rod
    SQL>
    Steve

  • Using a sequence inside BEFORE TRIGGER

    Hi all,
    I just created a testtable and a sequence to use as a primary key column value for that table.
    I tried to create a BEFORE INSERT trigger on that table and in the trigger i tried to set up the primary key column value using the sequence
    but while compiling i am getting the error "Error(9,30): PLS-00357: Table,View Or Sequence reference 'SEQ_OF_TESTTABLE.NEXTVAL' not allowed in this context"
    My Version:Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    All the objects created with the same user. I would appraciate any help, thanks all
    EDIT
    I solved the problem using the below
    create or replace
    TRIGGER Bef_Ins_On_Testtable
    BEFORE INSERT ON TestTable
    FOR EACH ROW
    declare
    ntemp_id INT;
    BEGIN
    SELECT SEQ_OF_TESTTABLE.NEXTVAL INTO ntemp_id FROM DUAL ;
    DBMS_OUTPUT.PUT_LINE('İNSERTED');
    :NEW.VSURNAME := 'HAKKİ' ;
    :NEW.NID := ntemp_id;
    END;But i wonder why i can use the sequence(just as seqeunce_name.NEXTVAL) in INSERT statement and why cant in trigger?
    Edited by: user9371286 on 31.Tem.2010 04:15
    Edited by: user9371286 on 31.Tem.2010 04:21
    Edited by: user9371286 on 31.Tem.2010 04:27

    Please post your trigger code and your database version ( the result of: select * from v$version; ).
    Put it between tags, so your example will stay formatted.
    (see: http://forums.oracle.com/forums/help.jspa for more examples regarding tags)
    "PLS-00357: Table,View Or Sequence reference "string" not allowed in this context
        Cause: A reference to database table, view, or sequence was found in an inappropriate context. Such references can appear only in SQL statements or (excluding sequences) in %TYPE and %ROWTYPE declarations. Some valid examples follow: SELECT ename, emp.deptno, dname INTO my_ename, my_deptno, my_dept .FROM emp, dept WHERE emp.deptno = dept.deptno; DECLARE last_name emp.ename%TYPE; dept_rec dept%ROWTYPE;
        Action: Remove or relocate the illegal reference."
    +http://download.oracle.com/docs/cd/B19306_01/server.102/b14219/plsus.htm#sthref13592+
    You can find examples of triggers referring to sequences here, by doing a search on this forum or:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_triggers.htm#ABC1032282                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Calling java class/procedure inside a trigger

    Hi all
    I want like to call a java procedure from a trigger.
    i know that i should load the class then write call specification and then call the java stored procedure.
    Before that what are the prerequisites ..
    Do i need to install java on my local machine?
    secondly for sample testing can you provide me a sample java code that will connect to my db and inserts some sample data into sample table
    regards
    raj

    Hi Here are the Details: I have the following
    Java File : Helloworld.java
    Class File : HelloWorld.class
    Location of Java and Class Files: C:\Program Files\Java\jdk1.6.0_13\
    Method : main(java.lang.String[])
    Helloworld.java
    class HelloWorldApp {
    public static void main(String[] args) {
    System.out.println("Hello World!"); // Display the string.
    loadjava -u HR/hr@ORCL C:\Program Files\Java\jdk1.6.0_13\HelloWorldApp.class ( From where should i run this command ?should i go to  windows--start--cmd  ? )
    CREATE OR REPLACE PROCEDURE sayhello ()
    AS LANGUAGE JAVA
    NAME 'HelloWorld.main(java.lang.String[])';
    CREATE OR REPLACE TRIGGER sal_trig
    AFTER UPDATE OF sal ON emp
    FOR EACH ROW
    CALL sayhello(); ------------------ ( where do i see the output when i call the procedure?)
    regards
    raj
    Edited by: raj_fresher on May 20, 2009 7:57 AM

  • How can I access user defined column(in query) inside the trigger?

    Hi
    I have 3 unions and each query displays different records on some criteria. I also have a column hard-coded
    Ex:
    select a.col1, a.col2,
    add as update
    from table1 a
    where ...
    union
    select a.col1, a.col2,
    change as update
    from table1 a
    where ...
    union
    select a.col1, a.col2,
    del as update
    from table1 a
    where ...
    And I need to display a column in the report only if update is Add. I was thinking of writing a format trigger for that field. But I do not know how can I access this user defined column named update in the trigger?
    Any help?

    Try ":update" minus the double-quotes. Ex:
        IF :update = 'add' THEN
          RETURN(TRUE);
        ELSE
          RETURN FALSE;
        END IF;
    You'll want to place your hard-coded values in single-quotes. Ex:
        select a.col1, a.col2,
        'add' as update
    - Brian

  • How to call a procedure inside a trigger?

    hi people,
    I have a trigger which cals a stored proc named PY.but i couldn get dis trigger worked out.can u pls sugges me?.the trigger is as follows.
    create or replace trigger ts after insert on s
    for each row
    begin
    call py
    if this trigger gets successfully created its enough for me.gimme some ideas.Thanks in advance.
    regards
    VIDS

    Hi,
    create or replace trigger ts after insert on s
    for each row
    begin
    call py
    just call 'py' no need of calling 'call py'.....
    create or replace trigger ts after insert on s
    for each row
    begin
    py;
    If it helps mark question as anwered or helpfull....
    Thanks,
    Pavan

  • Get Table Columns inside a Trigger

    I am currently working on triggers. Is there a way to retrieve all the columns of the table where the trigger is associated to? I got a way to get columns a table using the query below.
    select column_name from all_tab_columns
    where table_name = 'tablename'
    and owner = 'ownername'
    But is there other way?

    Hi ,
    Unfortunately , i don't think that there is a 'dynamic' solution to your problem....
    I'm facing the same problem ....see the below post...
    Getting the columns of a table which are inserted/updated via db trigger
    Regards,
    Simon

  • Re: audit using ddl trigger for dcl (grant and revoke)

    Why are you trying to re-invent oracle's own auditing feature?

    No, there is no way to unbranch.
    I'll lock this branch and you can answer Ed on your original thread (I'll leave it to you to copy/paste Ed's question in your reply).

  • Mutating Error problem using audit trigger for UPDATE

    I need to add 4 columns to all of my tables named:
    INSERT_BY
    INSERT_DATA
    UPDATE_BY
    UPDATE_DATE
    I intend these to act as "inserted" and "last updated" audit trails within the table, as opposed to creating a new table and storing the audit information there. The insert columns appear to be easy, as I can just use a DEFAULT clause within the definition of the table. However when I attempted to write a (my first) trigger then I run into problems with mutating tables. Presumebly because I am attempting to change the table while the trigger is referencing it.
    create or replace trigger test_audit
    after update on dictionary
    begin
    update dictionary
    set update_by = user, update_date = sysdate
    where entity_id = :old.entity_id;
    end;
    I thought I could maybe get around this by calling a procedure from inside the trigger. Something like:
    create or replace procedure test_audit(vColumn in varchar2, vData in varchar2, vTable in varchar2) is
    -- vTable is table name
    -- vColumn is PK of table
    -- vData is value of PK in current row
    begin
    update vTable
    set update_by = user, update_date = sysdate
    where vColumn = vData;
    commit;
    end test_audit;
    However I cannot use variable for table names. Will this mean I have to create a procedure for each table/trigger? Is there a way to reference the table name as a variable and keep this a generic procedure? Or is there an easier way to record the auditing UPDATE information for each changed row within the original table?
    Many thanks in advance......

    Will
    this mean I have to create a procedure for each
    table/trigger? I think you've answered that question already.
    Is there a way to reference the table
    name as a variable and keep this a generic procedure?Not that I'm aware of.
    Or is there an easier way to record the auditing
    UPDATE information for each changed row within the
    original table?Well, there's the AUDIT feature.
    C.

  • Passing variables to a procedure inside a database trigger

    Hi,   I am new to oracle Forms . I am having a table in database . For that table i had written a database trigger which will fire after insert or update . I am using a procedure inside the Trigger . I want to pass arguments to the procedure which is being called in the trigger . The variables which i want to pass to the procedure are one is a primary key and the other is a normal cloumn which are in the same table for which the trigger is written. Can anybody help me regarding this.?

    > But when i m calling it with forms i m getting an error
    You cannot call a database trigger from forms. A trigger is part of the table, e.g.:
    create trigger my_trigger
    before insert or update or delete on my_table
    for each row

  • Audit on Trigger Enable/Disable

    Hi all,
    I have created a trigger on a table. It works fine. After one year I checked the data generated by trigger. It has some missing data. I want to know is there any audit trail which can be used to trace who has enabled/disabled my trigger.
    Any help will be appreciated.
    Thanks
    Kritika.

    Hello
    Did you read any of the guide? There are numerous links to the SQL syntax guide for AUDIT
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_4007.htm#i2059073
    In it you will find specific references to how to audit ALTER TRIGGER statements. i.e
    AUDIT ALTER ON <trigger name>
    HTH
    David

Maybe you are looking for

  • Firefox home wont recognize my username

    I have a firefox account and loaded firefox sync on my desktop, but firefox home wont let me log it "username not found"

  • ABAP Practice Interface

    Hi.. Our company has signed for the SAP ERP whereas i've been assigned with the ABAP module. I'm gathering some informations through web parellel to the training classes in progress.. May i know, if i can use some ABAP Interface on my local PC to pra

  • ALEAUD - ALE -IDOC

    Hi, I have doubt in ALE-IDOC. I would like to modify message that would get send from ALEAUD for which i am looking for function module or available user exits. Please let me know if u have any idea about it. Thanks Parag

  • What is error code 2324?

    What is iTunes error code 2324?

  • Authorization restriction for Transaction PK13N

    Hi @ all My colleagues and I are responsible for the authorizations in our system. Since few days we test the Kanban functions in SAP. In abovementioned transaction are two buttons "To Empty" and "To Full". Does anybody know if there is a possibility