🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.databases.oracle.misc
Article #102

Re: Audit Trigger

#102
From: Connor McDonald
Date: Fri, 24 Aug 2001 09:04
62 lines
3693 bytes
Adriaan Nortje wrote:
> 
> Hi
> 
> I'm trying to create a generic audit trigger (after update) which will
> select from user_tab_colums all the columns of the table and then go
> evaluate the :old. and :new. values for each colun to see whether there was
> an updte done on the column and insert it into an audit table.
> 
> what I was thinking of doing, is something like this.
> 
> create or replace trigger audit_trigger
> after update or insert ot delete on employees for each row
> 
> declare
>     cursor aud_cur is select column_name , column_type from user_tab_columns
> where table_name = 'employees';
> 
> begin
>     if updating then
>         for aud_row in aud_cur loop
>             ------here is my problem -----
>             if :old.aud_row.column_name <> :new.aud_row.column_name then
>                 insert into audit_table values (:old.aud_row.column_name,
> :new.aud_row.column_name)
> 
> --- bla, bla, bla
> 
> as you can see this will clearly not work. What needs to be done is that I
> need the value of the column_name and somehow get the :old. and :new. value
> for that column_name's value (if that makes any sense at all). In a normal
> procedure I would have been able to select two values like these using
> NATIVE DYNAMIC SQL, but as this is a trigger I can not and any attempt to
> query the table again will result in a mutation error and then I still only
> have one value (if you can get around the mutation)
> 
> Oracle's auditing features don'r allow for auditing of column specific
> auditing and can only tell me that the table has been access for an update.
> Also, passing the column_name to a external procedure (like Pro C++) would
> result in errors and still I have no new and old values.
> 
> I've been trying to find a function in PL similar to Developer's namein
> function which will do exactly what is required, but I haven't had any luck
> yet.
> 
> So, PLEASE help me.
> 
> GREAT.

You need another layer of abstraction, ie, write a little script that
will generate all the trigger code (using user_tab_columns to do it) for
each table that you want to monitor.

hth
connor  
-- 
==============================
Connor McDonald

http://www.oracledba.co.uk

"Some days you're the pigeon, some days you're the statue..."
Technical Details
Message-ID: <3B8618B7.33FE@yahoo.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.ems.psu.edu!news.cis.ohio-state.edu!news.maxwell.syr.edu!diablo.theplanet.net!news.theplanet.net!not-for-mail
References: <3b83f0b8$0$233@hades.is.co.za>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb53f,a1a681ba7adb1d04
X-Google-Attributes: gidfb53f,public
X-Google-Thread: f99a8,a1a681ba7adb1d04
X-Google-Attributes: gidf99a8,public
X-Google-Thread: f5464,a1a681ba7adb1d04
X-Google-Attributes: gidf5464,public
X-Google-Thread: fa4f9,a1a681ba7adb1d04
X-Google-Attributes: gidfa4f9,public
X-Google-ArrivalTime: 2001-08-24 06:52:57 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.ems.psu.edu!news.cis.ohio-state.edu!news.maxwell.syr.edu!diablo.theplanet.net!news.theplanet.net!not-for-mail
From: Connor McDonald <connor_mcdonald@yahoo.com>
Newsgroups: comp.databases.oracle.misc,comp.databases.oracle.server,comp.databases.oracle.tools,hannover.uni.comp.oracle
Subject: Re: Audit Trigger
Date: Fri, 24 Aug 2001 10:04:55 +0100
Lines: 62
Message-ID: <3B8618B7.33FE@yahoo.com>
References: <3b83f0b8$0$233@hades.is.co.za>
Reply-To: connor_mcdonald@yahoo.com
NNTP-Posting-Host: modem-125.new-york.dialup.pol.co.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: news5.svr.pol.co.uk 998643938 18980 62.137.83.125 (24 Aug 2001 09:05:38 GMT)
NNTP-Posting-Date: 24 Aug 2001 09:05:38 GMT
X-Complaints-To: abuse@theplanet.net
X-Mailer: Mozilla 3.01 (WinNT; I)
To: Adriaan Nortje <gandalf@nol.co.za>