Audit trigger

Hello

I have a TABLE LIKE this

CREATE TABLE emp_hr

(id                             NUMBER ,

hr_code VARCHAR2 (6 BYTE),

hr_unit VARCHAR2 (3 BYTE),

effect_date DATE,

EXPIRY_DATE DATE,

crtd_by VARCHAR2 (10 BYTE),

crtd_dt DATE,

updt_by VARCHAR2 (10 BYTE),

updt_dt DATE,

email_ID VARCHAR2 (50 BYTE),

comp_code VARCHAR2 (3 BYTE),

main_code VARCHAR2 (3 BYTE))

/

CREATE TABLE audit_tbl - Table of Audit

(id NUMBER,

MODIFIED_DATE DATE,

Modified_By VARCHAR2 (100 BYTE),

event_type VARCHAR2 (100 BYTE),

schema VARCHAR2 (30 BYTE),

ip_address VARCHAR2 (20 BYTE),

tNom VARCHAR2 (30 BYTE),

CNAME VARCHAR2 (30 BYTE),

old_val VARCHAR2 (2000 BYTE),

new_val VARCHAR2 (2000 BYTE),

pk_cols VARCHAR2 (2000 BYTE))

I am utter AUDIT TRIGGER on that TABLE.

I have a PACKAGE LIKE this

CREATE OR REPLACE

package audit_pkg

as

procedure check_val (l_id in number,

l_date to date,

l_modified_by in varchar2,

l_event_type in varchar2,

l_ip_address in varchar2,

l_tname in varchar2,

l_cname in varchar2,

l_new in varchar2,

l_old in varchar2,

l_pkval in varchar2);

procedure check_val (l_id in number,

l_date to date,

l_modified_by in varchar2,

l_event_type in varchar2,

l_ip_address in varchar2,

l_tname in varchar2,

l_cname in varchar2,

l_new to date,

l_old to date,

l_pkval in varchar2);

procedure check_val (l_id in number,

l_date to date,

l_modified_by in varchar2,

l_event_type in varchar2,

l_ip_address in varchar2,

l_tname in varchar2,

l_cname in varchar2,

l_new number,

l_old number,

l_pkval in varchar2);

end

CREATE OR REPLACE

audit_pkg package body

as

procedure check_val (l_id in number,

l_date to date,

l_modified_by in varchar2,

l_event_type in varchar2,

l_ip_address in varchar2,

l_tname in varchar2,

l_cname in varchar2,

l_new in varchar2,

l_old in varchar2,

l_pkval in varchar2)

is

Start

If (l_new <>l_old or)

(l_new is null and l_old is not NULL) or

(l_new is not null and l_old is NULL))

then

insert into audit_tbl

(id, modified_date, schema, modified_by, event_type, ip_address, tNom, cname, old_val, new_val, pk_cols) values

(l_id, l_date, user, l_modified_by, l_event_type, l_ip_address, upper (l_tname), upper (l_cname), l_old, l_new, l_pkval);

end if;

end;

procedure check_val (l_id in number,

l_date to date,

l_modified_by in varchar2,

l_event_type in varchar2,

l_ip_address in varchar2,

l_tname in varchar2,

l_cname in varchar2,

l_new to date,

l_old to date,

l_pkval in varchar2)

is

Start

If (l_new <>l_old or)

(l_new is null and l_old is not NULL) or

(l_new is not null and l_old is NULL))

then

insert into audit_tbl

(id, modified_date, schema, modified_by, event_type, ip_address, tNom, cname, old_val, new_val, pk_cols) values

(l_id, l_date, user, l_modified_by, l_event_type, l_ip_address,

Upper (l_tname), upper (l_cname).

TO_CHAR ("l_old," hh24:mi:ss of mon-dd-yyyy ").

TO_CHAR ("l_new," hh24:mi:ss of mon-dd-yyyy ").

l_pkval);

end if;

end;

procedure check_val (l_id in number,

l_date to date,

l_modified_by in varchar2,

l_event_type in varchar2,

l_ip_address in varchar2,

l_tname in varchar2,

l_cname in varchar2,

l_new number,

l_old number,

l_pkval in varchar2)

is

Start

If (l_new <>l_old or)

(l_new is null and l_old is not NULL) or

(l_new is not null and l_old is NULL))

then

insert into audit_tbl

(id, modified_date, schema, modified_by, event_type, ip_address, tNom, cname, old_val, new_val, pk_cols) values

(l_id, l_date, user, l_modified_by, l_event_type, l_ip_address, upper (l_tname), upper (l_cname),)

l_old, l_new, l_pkval);

end if;

end;

I created a TRIGGER LIKE this

CREATE OR REPLACE TRIGGER AUD_EMP_HR AFTER

DELETE OR UPDATE

ON EMP_HR

REFERRING AGAIN AS NINE OLD AND OLD

FOR EACH LINE

BEGIN

DECLARE

date of v_dt;

number of v_id;

v_type varchar2 (10);

v_modified_by varchar2 (100);

v_ip_address varchar2 (20);

BEGIN

v_dt: = sysdate;

Select seq_audit_trail.nextval in the double v_id;

If the update can

v_type: = 'UPDATE ';

Elsif deletion then

v_type: = 'DELETE ';

End if;

v_modified_by: = NVL (SUBSTR (SYS_CONTEXT ("' USERENV ', 'HOME'), 1, 30), USER);

audit_pkg.check_val (v_id, v_dt, v_modified_by, v_type, v_ip_address, 'EMP_HR', 'ID',: new.ID,:old.ID,:OLD.ID);

audit_pkg.check_val (v_id, v_dt, v_modified_by, v_type, v_ip_address, 'EMP_HR', 'HR_CODE',: new.HR_CODE,:old.HR_CODE,:OLD.ID);

audit_pkg.check_val (v_id, v_dt, v_modified_by, v_type, v_ip_address, 'EMP_HR', 'HR_UNIT',: new.HR_UNIT,:old.HR_UNIT,:OLD.ID);

audit_pkg.check_val (v_id, v_dt, v_modified_by, v_type, v_ip_address, 'EMP_HR', 'EFFECT_DATE',: new.) EFFECT_DATE,: old. EFFECT_DATE,:OLD.ID);

audit_pkg.check_val (v_id, v_dt, v_modified_by, v_type, v_ip_address, 'EMP_HR', 'EXPIRY_DATE',: new.) EXPIRY_DATE,: old. EXPIRY_DATE,:OLD.ID);

audit_pkg.check_val (v_id, v_dt, v_modified_by, v_type, v_ip_address, 'EMP_HR', 'EMAIL_ID',: new.) EMAIL_ID,: old. EMAIL_ID,:OLD.ID);

v_dt: = null;

v_id: = null;

v_type: = null;

v_modified_by: = null;

v_ip_address: = null;

END;

End;

I get this error...

PLS-00307: too many statements of "CHECK_VAL" corresponds to this call.

I can't understand why I get this error.

As stated by John Spencer, replace "l_pkval in varchar2" "l_pkval number" and it will compile.

And you don't need to repeat your logic in three procedures. Keep only the varchar2 one and let the other call two overloaded procedures it:

procedure check_val (l_id in number,

l_date to date,

l_modified_by in varchar2,

l_event_type in varchar2,

l_ip_address in varchar2,

l_tname in varchar2,

l_cname in varchar2,

l_new to date,

l_old to date,

l_pkval number)

is

Start

() check_val

l_id

l_date

l_modified_by

l_event_type

l_ip_address

l_tname

l_cname

TO_CHAR (l_new, 'dd-mon-yyyy hh24:mi:ss')

TO_CHAR (l_old, 'dd-mon-yyyy hh24:mi:ss')

l_pkval

);

end;

Tags: Database

Similar Questions

  • Verification of SQL trigger

    Hello gentlemen and Gentleladies:

    Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product

    Y at - it an easier way to write the Sub audit trigger?  Thank you for your help.

    create or replace 
    TRIGGER BI_AUD_TASK AFTER
      UPDATE ON TASK FOR EACH ROW 
      WHEN (
      NEW.TASK <> OLD.TASK
      OR OLD.TS_OWNER <> NEW.TS_OWNER
      OR OLD.TARGET_DATE <> NEW.TARGET_DATE
      OR OLD.IMPACT <> NEW.IMPACT
      OR OLD.STATUS <> NEW.STATUS
      OR OLD.COMMENTS <> NEW.COMMENTS
      OR OLD.ENTERED_BY <> NEW.ENTERED_BY
      OR OLD.TASK_TYPE <> NEW.TASK_TYPE
      OR OLD.DATE_CLOSED <> NEW.DATE_CLOSED
      OR OLD.TASK_START <> NEW.TASK_START
      OR OLD.TASK_PROG <> NEW.TASK_PROG
      OR OLD.DEPT <> NEW.DEPT
      OR (OLD.TASK IS NULL AND NEW.TASK IS NOT NULL)
      OR (OLD.TASK IS NOT NULL AND NEW.TASK IS NULL)
      OR (OLD.TS_OWNER IS NULL AND NEW.TS_OWNER IS NOT NULL)
      OR (OLD.TS_OWNER IS NOT NULL AND NEW.TS_OWNER IS NULL)  
      OR (OLD.TARGET_DATE IS NULL AND NEW.TARGET_DATE IS NOT NULL)
      OR (OLD.TARGET_DATE IS NOT NULL AND NEW.TARGET_DATE IS NULL) 
      OR (OLD.IMPACT IS NULL AND NEW.IMPACT IS NOT NULL)
      OR (OLD.IMPACT IS NOT NULL AND NEW.IMPACT IS NULL) 
      OR (OLD.STATUS IS NULL AND NEW.STATUS IS NOT NULL)
      OR (OLD.STATUS IS NOT NULL AND NEW.STATUS IS NULL) 
      OR (OLD.COMMENTS IS NULL AND NEW.COMMENTS IS NOT NULL)
      OR (OLD.COMMENTS IS NOT NULL AND NEW.COMMENTS IS NULL)
      OR (OLD.ENTERED_BY IS NULL AND NEW.ENTERED_BY IS NOT NULL)
      OR (OLD.ENTERED_BY IS NOT NULL AND NEW.ENTERED_BY IS NULL)
      OR (OLD.TASK_TYPE IS NULL AND NEW.TASK_TYPE IS NOT NULL)
      OR (OLD.TASK_TYPE IS NOT NULL AND NEW.TASK_TYPE IS NULL)
      OR (OLD.DATE_CLOSED IS NULL AND NEW.DATE_CLOSED IS NOT NULL)
      OR (OLD.DATE_CLOSED IS NOT NULL AND NEW.DATE_CLOSED IS NULL)
      OR (OLD.TASK_START IS NULL AND NEW.TASK_START IS NOT NULL)
      OR (OLD.TASK_START IS NOT NULL AND NEW.TASK_START IS NULL)
      OR (OLD.TASK_PROG IS NULL AND NEW.TASK_PROG IS NOT NULL)
      OR (OLD.TASK_PROG IS NOT NULL AND NEW.TASK_PROG IS NULL)
      OR (OLD.DEPT IS NULL AND NEW.DEPT IS NOT NULL)
      OR (OLD.DEPT IS NOT NULL AND NEW.DEPT IS NULL)
      ) 
      BEGIN IF UPDATING THEN
      INSERT
      INTO AUD_TASK
        (
          TASK_ID,
          OLD_TASK,
          NEW_TASK,
          OLD_TS_OWNER,
          NEW_TS_OWNER,
          OLD_TARGET_DATE,
          NEW_TARGET_DATE,
          OLD_IMPACT,
          NEW_IMPACT,
          OLD_STATUS,
          NEW_STATUS,
          OLD_COMMENTS,
          NEW_COMMENTS,
          OLD_ENTERED_BY,
          NEW_ENTERED_BY,
          OLD_TASK_TYPE,
          NEW_TASK_TYPE,
          OLD_DATE_CLOSED,
          NEW_DATE_CLOSED,
          OLD_TASK_START,
          NEW_TASK_START,
          OLD_TASK_PROG,
          NEW_TASK_PROG,
          DATE_TIME,
          APP_USER,
          OLD_DEPT,
          NEW_DEPT
    )
        VALUES
        (
          :NEW.TASK_ID,
          :OLD.TASK,
          :NEW.TASK,
          :OLD.TS_OWNER,
          :NEW.TS_OWNER,
          :OLD.TARGET_DATE,
          :NEW.TARGET_DATE,
          :OLD.IMPACT,
          :NEW.IMPACT,
          :OLD.STATUS,
          :NEW.STATUS,
          :OLD.COMMENTS,
          :NEW.COMMENTS,
          :OLD.ENTERED_BY,
          :NEW.ENTERED_BY,
          :OLD.TASK_TYPE,
          :NEW.TASK_TYPE,
          :OLD.DATE_CLOSED,
          :NEW.DATE_CLOSED,
          :OLD.TASK_START,
          :NEW.TASK_START,
          :OLD.TASK_PROG,
          :NEW.TASK_PROG,
          SYSTIMESTAMP,
          V('APP_USER'),
          :OLD.DEPT,
          :NEW.DEPT
        );
    END IF;
    END BI_AUD_TASK;
    

    May be less than the blog will help you.

    https://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:59412348055

    BR,

    Patrick

  • Relaxation for the audit data.

    Hi all

    I would like to rrre to write a trigger that maintains the auditing information.

    We have two tables. 1 2 EMP. EMP_AUDIT.

    If I do all DML operations or any other predefined on EMP table that verify information must INSERT into table EMP_AUDIT.

    Can you please let me know how to write a trigger for this.

    Thank you.

    This is called re - invent the wheel. Why opt for it?

    Have you considered maintenance efforts while suggesting the solution? How is it easy to replicate when given the need for another table of audit?

    You already have audit functionality provided by Oracle to take care of the check. Why not reuse the functionality rather that rebuild?

    This link here gives a demonstration step by step to enable the feature.

    In addition, the example does not ask for OP. Could there be updated or insert operations that may be interested in OP. With your path, he would need to create three different triggers.

    Here is an example to do only once:

    drop table test_table;
    drop table test_table_hist;

    create table test_Table (pk_col number primary key, col1 number, col2 varchar2(5));

    create table test_table_hist (pk_col number, old_col1 number, new_col1 number, old_col2 varchar2(5), new_col2 varchar2(5), operation varchar2(10), mod_time timestamp);

    create or replace trigger trg_test_table_history
    before insert or delete or update of col1, col2
    on test_table
    for each row
    begin
      if inserting then
        insert into test_table_hist (pk_col, new_col1, new_col2, operation, mod_time)
        values (:new.pk_col, :new.col1, :new.col2, 'Insert', systimestamp);
      elsif updating then
        insert into test_table_hist (pk_col, old_col1, new_col1, old_col2, new_col2, operation, mod_time)
        values (:new.pk_col, :old.col1, :new.col1, :old.col2, :new.col2, 'Update', systimestamp);
      else
        insert into test_table_hist (pk_col, old_col1, old_col2, operation, mod_time)
        values (:old.pk_col, :old.col1, :old.col2, 'Delete', systimestamp);
      end if;
    end;

    insert into test_table values (1, 1001, 'ABCD');
    update test_table set col2 = 'ABCDZ' where pk_col = 1;
    insert into test_table values (2, 1002, 'PQRS');
    delete from test_table where pk_col = 2;

    commit;

    select *
      from test_table_hist;

    PK_COL                 OLD_COL1               NEW_COL1               OLD_COL2 NEW_COL2 OPERATION  MOD_TIME                 
    ---------------------- ---------------------- ---------------------- -------- -------- ---------- -------------------------
    1                                             1001                            ABCD     Insert     04-FEB-13 06.50.58.926695000 AM
    1                      1001                   1001                   ABCD     ABCDZ    Update     04-FEB-13 06.50.59.099346000 AM
    2                                             1002                            PQRS     Insert     04-FEB-13 06.50.59.264155000 AM
    2                      1002                                          PQRS              Delete     04-FEB-13 06.50.59.427643000 AM

    Post edited by: PurveshK added Audit trigger for example

  • ORA_ROWSCN continues to increase without any DML

    Hi Experts,

    I use ORA_ROWSCN in ETL for the incremental data capture.
    Problem is that the ORA_ROWSCN continue to increase for some table without any DML.
    Table have ROWDEPENDENCIES.
    There is no audit, trigger, or batch running on the tables.
    Database is 11.2.0.3 on Windows 64 bit OS.
    ETLs perform DML heavy overnight. During the day, max (ORA_ROWSCN) continues to rise for a few tables.

    I noticed that during the questioning of a few paintings, SCN_TO_TIMESTAMP (max (ORA_ROWSCN)) has shown the current timestamp.

    Can cause the "delayed block drain plug" this?
    If this is not the case, is it then any other bug cause or identified?
    Is there enough reliable ORA_ROWSCN?

    Thank you
    Santosh kumar

    Welcome to the forum!
    >
    I use ORA_ROWSCN in ETL for the incremental data capture.
    Problem is that the ORA_ROWSCN continue to increase for some table without any DML.
    Table have ROWDEPENDENCIES.
    There is no audit, trigger, or batch running on the tables.
    Database is 11.2.0.3 on Windows 64 bit OS.
    ETLs perform DML heavy overnight. During the day, max (ORA_ROWSCN) continues to rise for a few tables.

    I noticed that during the questioning of a few paintings, SCN_TO_TIMESTAMP (max (ORA_ROWSCN)) has shown the current timestamp.

    Can cause the "delayed block drain plug" this?
    If this is not the case, is it then any other bug cause or identified?
    Is there enough reliable ORA_ROWSCN?
    >
    Congrats on being one of the few to ask a question which is, as Arte Johnson (of Laugh-In fame) would say, "very interesting".

    Unfortunately for us, you have also provided your own answer! ;)

    Drain plug can cause that? Yes - one of the oddities of the drain plug delay block even with a table by using ROWDEPENDENCIES is that Oracle may not always determine the exact SCN and therefore can use slightly more high when finished.

    Reliable? Yes - ORA_ROWSCN is reliable enough. But, as you will see, you must force the Oracle to drain plug blocks before use ORA_ROWSCN to query the changes.

    The best discussion, which includes the code example, is on the site of challenge from PL/SQL to a fault, a year or two it is
    "Impact of the Serializable Transaction not seen by players (9622).
    http://PLSQL-challenge.blogspot.com/2012/01/rowdependencies-impact-not-seen-by.html

    Anyone with enough interest should read the entire article, long and many answers. You will find them VERY informative. I suggest you add this bookmark to your "Oracle Toolbox.

    I included only a short extract conclusions regarding your question here and the code example illustrating the it.
    >
    Smail:

    I wonder if the ROWDEPENDENCIES guarantees 100% accuracy
    ORA_ROWSCN for each line.
    As far as I understand it, it can still generate false positives, but much less, because each row has its own ORA_ROWSCN that is NOT affected if other lines in the block are updated or locked/jerks, but still can be slightly higher than that of true to the line itself when Oracle it cannot determine precisely when cleaning
    >
    And the answer with the code
    >
    _Nikotin:

    but maybe still slightly higher than that of true to the line itself when Oracle it cannot determine precisely when cleaning.

    Yes, here is the example of the impact of the delay block drain plug:

    drop table plch_test;
    drop table plch_test2;

    create table plch_test (number, varchar2 (100) tilte, number of val) rowdependencies;

    Start
    insert into plch_test values (1, 'creation and validation at level 1', 0);
    insert into plch_test values (2, 'to update and commit to step 2', 0);
    commit;
    end;
    /

    update the value val = 1 plch_test where a = 2;

    change the built-in system buffer_cache;

    commit;

    create table plch_test2 (number, varchar2 (100) tilte, number of val) rowdependencies;

    Start
    insert into plch_test2 values (3, 'create and commit to step 3', 0);
    insert into plch_test2 values (4, 'to update and commit 1e5 times in step 4', 0);
    commit;
    end;
    /

    Start
    because me in 1... loop 1E5
    Update plch_test2 the value val = val + 1 where a = 4;
    commit;
    end loop;
    end;
    /

    Select t.*, Yvert plch_test2 ora_rowscn t
    Union of all the
    Select t.*, plch_test ora_rowscn t
    order by SNA;

    After that, you can see that steps 2 and 3 are reversed in the query result:

    SQL > select t.*, Yvert plch_test2 ora_rowscn t
    2 Union all the
    3. Select t.*, plch_test ora_rowscn t
    4 order of SNA;

    A VAL TILTE SNA
    ---------- -------------------------------------------- ---------- ----------
    1. create and validation, to 1 0 1998971227 step
    3. create and validation, to step 3 0 1998971254
    2 update and validation, 2 1 1999009794 step
    4 update and commit times in step 4 100000 1999224125 1e5
    >
    You can see from the above result to the effect that you get

  • Who tried to log in - e-business

    Hello


    Oracle 11.5.9 / 9i DB - is there anyway to tell who tried to connect to the application - i.e. get log in the user's network.

    (Yes I know this is e-business, I've posted it here because electronic commerce tends to be functional rather than technical style questions)


    Thank you

    Robert.

    Robert Angel wrote:
    Thank you to do this, in the worst case scenario I can use this in an audit trigger, but can tell me if there are all the standard tables that capture these environment variables in the database, so I can access historical data?

    Kind regards

    Robert.

    Not by default, but there may be something in Fine grain auditing Oracle you can use...

    http://www.Oracle.com/technetwork/database/security/index-083815.html

  • How to know the registration State in SQL

    I want to use a database trigger that will push the data into a table of audit use from one table to another table can you please tell me the order how can I recognize the status of the registration, is it INSERT, UPDATE or DELTE
    because I want to PUSH 'I' to insert "D" to delete and 'U' for update

    So what is the command for the status of the record in sql and I want only 1 trigger that will do

    Thank you

    Hello

    the status of the registration, is it INSERT, UPDATE or DELTE

    It is not on the status of the record, but if your trigger fires wile insert/update / delete.
    You can code in your trigger:

    some pseudo-code of trigger:

    If the insertion
    then
    : NEW. ACTION: = 'I '.
    elsif update
    then
    : NEW. ACTION: = "U".
    elsif removal
    then
    : OLD. ACTION: = A '
    end if;

    You can find many examples on this forum, just do a search on "audit trigger."

    See f.i.: the implementation of triggers to audit on several tables

  • Audit of drop trigger instructions

    Hi all

    I want to review the status of any user drop trigger. I tested it by creating a generic user, a table and a trigger on the table. Then, I dropped the trigger and went to the notice of dba_audit_trail to check if there is no record this action. There is none.

    SQL> audit drop any trigger whenever successful;
    
    
    Audit succeeded.
    
    
    SQL> audit drop any trigger whenever not successful;
    
    
    Audit succeeded.
    
    
    SQL> create user test_trg identified by "test_trg123";
    
    
    User created.
    
    
    SQL> grant connect, resource, select_catalog_role to test_trg;
    
    
    Grant succeeded.
    
    
    SQL> conn test_trg/test_trg123
    Connected.
    SQL> create table t (id number primary key);
    
    
    Table created.
    
    
    SQL> create trigger test_trigger before insert on t for each row begin null; end;
      2  /
    
    
    Trigger created.
    
    
    SQL> drop trigger test_trigger;
    
    
    Trigger dropped.
    
    
    

    Then, I questioned the DBA_AUDIT_TRAIL and found no documents reflecting the DROP TRIGGER TEST_TRIGGER statement that I just executed.

    SQL> SELECT USERNAME, ACTION_NAME, TIMESTAMP FROM DBA_AUDIT_TRAIL WHERE ACTION_NAME NOT LIKE 'LOG%';
    
    
    USERNAME                       ACTION_NAME                  TIMESTAMP
    ------------------------------ ---------------------------- ---------
    SYSTEM                         DROP PUBLIC SYNONYM          26-FEB-15
    SYSTEM                         DROP PUBLIC SYNONYM          26-FEB-15
    SYSTEM                         CREATE PUBLIC SYNONYM        26-FEB-15
    SYSTEM                         CREATE PUBLIC SYNONYM        26-FEB-15
    

    Where is my mistake?

    Thank you.

    Martin

    You level DROP ANY TRIGGER, this been verified if TEST_TRG user deleted a trigger to another schema, not his own.

    turn on: trigger access check;

    -recreate the trigger in the test_trg schema

    -to connect with test_trg, put his own trigger

    -check the audit records

  • We must register if the trigger was disable

    Hi all

    Will have one of the scenarios,

    If the trigger has been disabled, then we need to insert another table through trigger for the details of the audit, if possible.

    Please tel me your suggestion...

    I thank in advance

    If I understand, you want to detect when a person turns off a trigger?  What if a person disabled, for example by causing an error in an addiction? It is difficult to trigger detection.

    Anyway if the first case, you could add a DDL on "AFTER ALTER" trigger on the schema or DB you want to monitor.  I wouldn't not recommend myself well.  But something like...

    create or replace trigger AASCH_TRIGGER after alter on schema

    declare

    vOwner varchar2 (30);

    VNAME varchar2 (30);

    vType varchar2 (30);

    vStatus varchar2 (50);

    Start

    Select ora_dict_obj_owner, ora_dict_obj_name, ora_dict_obj_type

    in vOwner, vname, vType

    Double;

    If ora_dict_obj_type = "TRIGGER" then

    Select the STATE

    in vStatus

    from user_triggers

    where trigger_name = VNAME;

    If vStatus <> 'ACTIVE' then

    -Do something, e-mail or other

    end if;

    end if;

    end;

    /

  • DDL trigger

    Hello

    I tried DDL audit for help from under the sql statement,

    Audit on schema.tablename by access;

    This can be disabled by the No. AUDIT statement by the owner of the table.

    Please suggest me if DDL trigger can be used, if so, please help me with the script to create the trigger so that the DDL statement issued by the owner of the table can be monitored and verified.


    I don't know exactly why you need, but here is an example of code to audit the DDL from a particular table

    ------------

    -Table to contain the audit entries

    create the table aud_log_btopg

    (

    VARCHAR2 (50) of the event.

    object_name varchar (1000).

    object_type varchar2 (50).

    action_date varchar2 (50).

    machine to varchar2 (50).

    program varchar2 (50).

    OSUSER varchar2 (50).

    dbuser varchar2 (50).

    sql_text varchar2 (1000)

    )

    /

    -Trigger to insert audit logging information in the table above

    create or replace trigger aud_ddl_btopg
    after create or alter or drop on &SCHEMA
    declare
      v_num NUMBER;
      sql_stmt varchar2(2000);
      sql_text ora_name_list_t;
      l_sysevent varchar2(50);
      l_obj_name varchar2(50);
      l_obj_type varchar2(50);
      l_machine varchar2(50);
      l_prog varchar2(50);
      l_osuser varchar2(50);
      l_username varchar2(50);
      l_date varchar2(100);
    begin
      -- if object of interest
      if ora_dict_obj_name = '&YOUR_TABLE' THEN
      -- get SQL executed
      v_num := ora_sql_txt(sql_text);
      FOR i in 1..NVL(v_num,0) LOOP
      sql_stmt:=sql_stmt||sql_text(i);
      END LOOP; 
      -- get the rest of the audit information
      select ora_sysevent,ora_dict_obj_name,ora_dict_obj_type,
      to_char(sysdate,'fm dd/Mon/yyyy HH:MI:SS AM'),
      machine,program,osuser,username into l_sysevent,l_obj_name,l_obj_type,l_date,l_machine,l_prog,l_osuser,l_username
      from v$session
      where audsid = sys_context( 'userenv', 'sessionid' ); 
      -- insert into audit table
      insert into aud_log_btopg values (l_sysevent,l_obj_name,l_obj_type,l_date,l_machine,l_prog,l_osuser,l_username,sql_stmt); 
      if ( sql%rowcount <> 1 )
      then
      raise_application_error
      ( -20001, 'Unable to id your session' );
      end if; 
      end if;
    end;
    /

    ----

    I would not recommend the use of this type of audit in the production databases. Do not try to reinvent the wheel and use that provides the database.

    Rgds,

    IonutC

  • SQL trace or audit?

    Dear friends, DBA,

    Version of DB - 11.1.0.7

    I have a situation where I have to trace SQLs run by a specific user. The user executes the action click in front end application and I need to follow what SQLs it is running in the database.

    This is not feasible with the tracing session level that the session ID changes in the course of the series click and go the actions performed by this user in the application.

    What would be an apt approach to follow the action performed by the user on the database? An option of the audit?

    Thank you.

    within the LOGON trigger you could do as below based on the value of the USER

    ALTER SESSION SET SQL_TRACE = TRUE;

  • APEX: Audit trail, what status of transaction has been validated

    Hi Expert, need your help fast

    I created an audit to capture file that made the changes and what has been done changes when

    never the Delete / Update / MRU /MRD is clicked

    The question is what is the transition_name to tell me that the user has clicked the button Delete or MRU, etc.

    while I can store in the Audit file.

    That is to say I don't know who, when and what the transition was done

    Hi JAS-Oracle,

    JAS-Oracle wrote:

    Hi Expert, need your help fast

    I created an audit to capture file that made the changes and what has been done changes when

    never the Delete / Update / MRU /MRD is clicked

    The question is what is the transition_name to tell me that the user has clicked the button Delete or MRU, etc.

    while I can store in the Audit file.

    That is to say I don't know who, when and what the transition was done

    I think you can use the trigger to achieve

    for example

    CREATE OR REPLACE TRIGGER  "MY_TABLE_BIU_TRG"
    BEFORE INSERT OR UPDATE
      ON MY_TABLE
      FOR EACH ROW
    BEGIN
      IF INSERTING THEN
          :NEW.CREATED_DATE := SYSDATE;
          :NEW.CREATED_BY := NVL (v ('APP_USER'), USER);
          :NEW.TRANSITION := 'Insert';
      END IF;
      IF UPDATING THEN
          :NEW.MODIFIED_DATE := SYSDATE;
          :NEW.MODIFIED_BY := NVL (v ('APP_USER'), USER);
          :NEW.TRANSITION := 'Update';
      END IF;
    
    END;
    

    Hope this will give you an idea.

    Kind regards

    Jitendra

  • Insert an Update statement in a Trigger

    I'm new to APEX and I'm trying to determine the best place to put an update for an audit table.

    This is the trigger that I work with:

    create or replace trigger "LEASES_T1"
    BEFORE
    insert or update or delete on "LEASES"
    for each row
    begin
        if inserting then
            :new.CREATION_DATE := sysdate;
            :new.created_by := nvl(v('APP_USER'),user);
            :new.last_update_date := sysdate;
            :new.last_update_by := nvl(v('APP_USER'),user);
    
        elsif updating then
            :new.last_update_date := sysdate;
            :new.last_update_by := nvl(v('APP_USER'),user);
        end if;
    
    end;
    INSERT INTO LEASE_AUDIT (LEASE_ID) VALUES (P2_ROWID);
    
    


    It is a basic triggers relaxation I raised a stock APEX.  It works fine without the addition of the audit at the end.  It updates the data created or changed for a table called LEASES.  During the same operation, I want to record this action in the audit table, LEASE_AUDIT.  The barebones for this statement is on line 18, above.

    Passing through some other posts which dealt with similar issues, it seemed that it would be timely to update in the trigger, but I don't know where it would go.  In this case, the statement is at the end, since it does not matter whether registration in the leases table exists or not.  The PK for LEASES is configured to be a ROWID generated by the screen (I have since been notified that a sequence may be a better method).

    So, how framing this statement to work?  Or is this oddball approach?

    I'm on APEX 4.2.4 on 11g.  My experience has been Access and VBA, mainly on autonomous databases (non-SQL Server backend).

    Thank you!

    I think a composed trigger may be the way to go.  I'll throw it against the wall and see if it sticks.

    Thank you!

  • Database trigger can not see the package global variable after assign in my form

    Hello

    I faced the problem with the trigger and the package variable global using the form designer

    first of all, I get the local IP address machine using WEBUTIL in triggering of the PREFORM and initialize my global package variable by ' Client_Info_Pkg.Set_IP_Address (WEBUTIL_CLIENTINFO.» GET_IP_ADDRESS); ", then I tried to make the DML operation in my form and at the same time I trigger database also uses the package global variable of" Client_Info_Pkg.Gand_IP_Address; "to read in the package, and then insert it into the audit table


    The question this database trigger may not feel the initialization "Client_Info_Pkg.Set_IP_Address (WEBUTIL_CLIENTINFO. GET_IP_ADDRESS)' I did in triggering of the PREFORM and I used to wonder if oracle create new session to run this trigger so he can't see my boot or what?!. .

    the package

    CREATE OR REPLACE PACKAGE Client_Info_Pkg

    Global_IP_Address VARCHAR2 (100);

    FUNCTION Get_IP_Address RETURN VARCHAR2;

    PROCEDURE Set_IP_Address (p_Machine_Name IN VARCHAR2);

    END Client_Info_Pkg;

    /

    CREATE OR REPLACE PACKAGE BODY Client_Info_Pkg

    FUNCTION Get_IP_Address RETURN VARCHAR2 IS

    BEGIN

    RETURN Global_IP_Address;

    END;

    PROCEDURE Set_IP_Address (p_IP_Address IN VARCHAR2) IS

    BEGIN

    Global_IP_Address: = p_IP_Address;

    END;

    END Client_Info_Pk

    relaxation

    --------------

    CREATE OR REPLACE TRIGGER RUNERP.FO_DOC_TYPES_L_T

    BEFORE INSERT OR UPDATE OR DELETE ON FO_DOC_TYPES

    REFERRING AGAIN AS NINE OLD AND OLD

    FOR EACH LINE

    BEGIN

    IF THE INSERTION

    RUN IMMEDIATELY ' INSERT INTO FO_DOC_TYPES_LOG

    VALUES ("I",: DOC_TYPE_ID,: DOC_TYPE_VALUE,: DOC_TYPE_NAME,: Vip_Address' HELP: NEW.) DOC_TYPE_ID,: NEW. DOC_TYPE_VALUE,: NEW. DOC_TYPE_NAME, Client_Info_Pkg.Get_IP_Address;

    END IF;

    IF THE UPDATE CAN

    RUN IMMEDIATELY ' INSERT INTO FO_DOC_TYPES_LOG

    VALUES ("U",: DOC_TYPE_ID,: DOC_TYPE_VALUE,: DOC_TYPE_NAME,: Vip_Address) "USING: NEW." DOC_TYPE_ID,: NEW. DOC_TYPE_VALUE,: NEW. DOC_TYPE_NAME, Client_Info_Pkg.Get_IP_Address;

    END IF;

    IF REMOVE THEN

    RUN IMMEDIATELY ' INSERT INTO FO_DOC_TYPES_LOG

    VALUES ("D",: DOC_TYPE_ID,: DOC_TYPE_VALUE,: DOC_TYPE_NAME,: Vip_Address) "USING: NEW." DOC_TYPE_ID,: NEW. DOC_TYPE_VALUE,: NEW. DOC_TYPE_NAME, Client_Info_Pkg.Get_IP_Address;

    END IF;

    END;

    /

    Thanks in advance

    I solved my problem by using the CONTEXT object, Michael thank you for your interest.

  • The audit only the command executed by third-party applications!

    Dear friends,

    Normally, we can check DML, DDL associated command by a user in oracle10g or oracle11g. But I want to check DML/DDL command that is only performed by an application such as SQL * more or Toad, etc..

    I mean that all DDL/DML commands are not checked. Audit only commands that are executed by a third party application like Toad, SQL * Plus etc.

    Is it possible in oracle 10g or 11g?

    > Audit only the commands that are executed by a third party application like Toad, SQL * Plus etc.

    As said by Sb, it is not possible because it is not possible. Purpose the audit is to verify who accessed what data at this time, not what application accessed what data right here. There not logic by which the application, the user has consulted the data.  Access to user data is logical and that is the purpose of the audit and that it is possible by audit (audit by by access ;) or trigger.)

    Concerning

    Girish Sharma

  • How to get the value to help trigger the poster or y at - it another option.

    Hello

    I have two tables emp and dept in the two table it is last_updatedatetime of column dating from stores over time, and there are a few more columns in both the table and the deptno is common in both table

    Then, I created a view using this table with readonly.

    now, I wanted to get these value from view if last_updatetime change in the base table and wanted to store only the data in a temporary table.

    Please help me to solve the above problem

    Thanks in advance

    I don't know y at - it another way, other than the triggers to audit changes. I wonder how a READ ONLY view (just SELECT the operation) could help fill some other temp table because you can't keep questioning the view at regular intervals. Instead, I would say, is to create a DML trigger on the table DEPT_EMP. Inside of the trigger call a stored procedure to control the corresponding State (WHERE the d.empno = e.empno AND e.emp_p_ind = 'Y').

Maybe you are looking for