Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8236717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:13:24+00:00 2026-06-07T19:13:24+00:00

I have created a trigger on a table which holds an audit log. When

  • 0

I have created a trigger on a table which holds an audit log. When a new entry is inserted I want to compare the new record with the latest existing record in the table (matching ID) column by column. If the value for one column has changed I want to execute an insert statement into another table. I have created the following PL SQL procedure:

CREATE OR REPLACE
TRIGGER PROJECT_BASELINE_ATTR_AUD_BI BEFORE INSERT
ON PROJECT_BASELINE_ATTR_AUD 
FOR EACH ROW
DECLARE 
  tab_name constant varchar2(32) := 'PROJECT_BASELINE_ATTR_AUD';
  col_name varchar2(32);
  v_latest_row PROJECT_BASELINE_ATTR_AUD%rowtype;
BEGIN
  -- get the record to compare with
  EXECUTE IMMEDIATE 'select * from  '||tab_name||
            ' where rev = (select max(rev) from '||tab_name||' where id = '|| :new.ID ||')' into v_latest_row;
FOR x IN (SELECT DISTINCT(COLUMN_NAME) FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = upper(tab_name)) 
  LOOP
  BEGIN
    col_name := x.column_name;
    -- do insert if the values are unequal
    -- IF :new.col_name <> v_latest_row.col_name
    --   INSERT INTO AUD_CHANGE_LOG VALUES (AUD_CHANGE_LOG_ID_SEQ.nextVal, :new.ID, :new.REV, tab_name, col_name);
  END;
  END LOOP;
END;

I know I could implement this with the real column name e.g.

IF :new.FOO <> v_latest_row.FOO
IF :new.BAR <> v_latest_row.BAR
...

but this would end up in a long if else cascade. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:13:25+00:00Added an answer on June 7, 2026 at 7:13 pm

    There is no way to refer new and old values of the trigger dynamically.

    You may develop a system that dynamically defines a trigger for each table structure you need, but it’s a hard job anyway.

    I did something like that and it’s not the kind of things you can finish in a couple of days.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i have created a trigger which i want to update a table field
We have created a table with a trigger that updates a ModifiedDate field in
I have a table where I created an INSTEAD OF trigger to enforce some
I have tried to perform update on table which was trigger by update on
I have created a a subclass of Table in my ASP.NET project which creates.
I have a table for which i have written a trigger: CREATE OR REPLACE
I have created materialized view (MV) on a table which is updated once in
I have a table trigger like below: CREATE OR REPLACE TRIGGER PAT_BUR_DOB_TRG BEFORE UPDATE
is is possible in postgres to have a trigger on CREATE TABLE that will
I have created a trigger in the xaml and it works fine. However, when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.