Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Generic Trigger to log changes

mail8mzSep 17 2021 — edited Sep 17 2021

Hello,
I am trying to use trigger to log the change of tables. However, it seems I have to hard code the column name and column value. Is there any generic solution regardless of the table structure?

Table structure:

CREATE table base_table ( id number(10), nm varchar2(10) );
CREATE table log_table ( id number(10), nm varchar2(10), logTs timestamp(6));

Table specific trigger works fine:

CREATE OR REPLACE TRIGGER trigger_spfc
  BEFORE UPDATE ON base_table
  FOR EACH ROW
BEGIN
    INSERT INTO log_table( id, nm, logTs)
      VALUES( :old.id, :old.nm, systimestamp);
 END;

I tried to make a more generic trigger using primary key column(eg, id) only. So that I only need hard code the primary key column, but not all columns in the table.


CREATE OR REPLACE TRIGGER trigger_generic
  BEFORE UPDATE ON base_table
  FOR EACH ROW
BEGIN
    INSERT INTO log_table( id, nm, histTS)
    SELECT id, nm, systimestamp from base_table 
    WHERE ID = :OLD.id;
 END;

Now I have "ORA-04091, table is mutating" error.
Any suggestion is welcome, thanks!

This post has been answered by Jan Gorkow on Sep 17 2021
Jump to Answer

Comments

Does anything in the chapter "INSTALLING PHP AND APACHE ON ORACLE SOLARIS" in http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html help?

pans_soul

Thanks, It was helpful in some sense but I still had to do some digging to come up with a working oci8. It did help in confirming which additional packages ie... system/headers were needed as pre-install steps. Also with the system variable settings (LD_LIBRARY_PATH) etc...

Still ran into trouble with installing oci8 though because the only offered solution was the "pecl" install and I do not have access to the internet on this box. I ultimately had to download the source code for oci8 and unpack it. Once that was done I was a little confused about the ./configure command since it didn't exist. I was ultimately able to find information on "phpize" which was the key to unpacking the source code and led to a successful compile.

The oracle client which was already installed on this box was a 64 bit client and the oci8 package seemed to require the 32 bit client libraries I wasn't comfortable trying to mess with the existing client so I went ahead and installed OIC instead and pointed to those libraries. I'm not sure if I'm just being too paranoid or if adding the 32 bit client libs to the existing oracle client is not that big of a deal. Thanks again.

Christopher Jones-Oracle

For anyone else coming across this thread, using phpize is shown on p77 of the book.

OCI8 builds fine with 64bit but the architecture of PHP will have determined what was used for the extension.

1 - 3

Post Details

Added on Sep 17 2021
20 comments
5,233 views