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 8066781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:06:24+00:00 2026-06-05T12:06:24+00:00

I have the following trigger which gets fired when updated becomes Y . I

  • 0

I have the following trigger which gets fired when updated becomes Y. I would like to insert the old values only if values do not exist in my_hist table. If the same record exists then it should not insert. For this best way is whether to create a constraint to check uniqueness in my_hist table or check this condition in trigger? If so how could I do this in trigger?

Or is it possible to check the unique constraint of my_hist table in trigger so that it will not insert duplicate records.

CREATE OR REPLACE TRIGGER mytrig
    AFTER UPDATE
    ON mytab
    FOR EACH ROW
WHEN (
new.updated = 'Y'
      )
BEGIN
    INSERT INTO my_hist
      VALUES   (
                        :old.id,
                        :old.no,                        
                        :old.start_date,
                        :old.end_date,
                        SYSDATE
                  );
END mytrig;
/
  • 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-05T12:06:25+00:00Added an answer on June 5, 2026 at 12:06 pm

    You can change your insert to the following in order to check if a duplicate exists already. The select assumes that the primary key of my_hist is id and start_date, change the where not exists clause to use only the primary key values if they’re different.

    insert into my_hist
    select :old.id, :old.no, :old.start_date, :old.end_date, sysdate
      from dual
     where not exists ( select 1
                          from my_hist
                         where id = :old.id
                           and start_date = :old.start_date
                               )
    

    However, this requires an index scan so it’s not that optimal.

    Instead let the exception get raised. It’s explicitly named: dup_val_on_index. If this does get raised then simply ignore it.

    BEGIN
        INSERT INTO my_hist
          VALUES   (
                            :old.id,
                            :old.no,                        
                            :old.start_date,
                            :old.end_date,
                            SYSDATE
                      );
    -- ignore an exception that get's raised if a duplicate value
    -- gets inserted. 
    EXCEPTION WHEN DUP_VAL_ON_INDEX then null;
    END mytrig;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the following MySQL query, which I would like to include in
I have the following insert trigger, which is essentially writing a duplicate row from
I have a trigger which deals with some data for logging purposes like so:
I have following trigger written for my application which gives me this error Msg
I have the following JQuery code which does similar functionality like Stackoverflow where the
I have the following code to trigger an alarm, which when it fires is
I have the following jQuery code which I like to convert to work with
I have the following function that is supposed to trigger anytime one of the
I have following requirement, I have C#/.Net console application, which refers to 'System.Data.Sqlite.dll' 'System.Data.Sqlite.dll'
I have the following JQ-Grid with a formatter function which returns some HTML as

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.