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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:49:46+00:00 2026-05-27T04:49:46+00:00

I have never created a trigger in Oracle before so I am looking for

  • 0

I have never created a trigger in Oracle before so I am looking for some direction.

I would like to create a trigger that increments an ID by one if the ID isnt in the insert statement.

The ID should start at 10000, and when a record is inserted the next ID should be 10001. If the insert statement contains a ID, it should override the auto increment.

ie

insert into t1 (firstname, lastname) values ('Michael','Jordan'),('Larry','Bird')

should look like:

firstname lastname id

Micahel Jordan 10000

Larry Bird 10001

insert into t1 (firstname, lastname, id) values ('Scottie','Pippen',50000)

should look like:

firstname lastname id

Micahel Jordan 10000

Larry Bird 10001

Scottie Pippen 50000

  • 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-05-27T04:49:47+00:00Added an answer on May 27, 2026 at 4:49 am

    Something like this will work on 11g

    CREATE SEQUENCE t1_id_seq 
      start with 10000 
      increment by 1;
    
    CREATE TRIGGER trigger_name
      BEFORE INSERT ON t1
      FOR EACH ROW
    DECLARE
    BEGIN
      IF( :new.id IS NULL )
      THEN
        :new.id := t1_id_seq.nextval;
      END IF;
    END;
    

    If you’re on an earlier version, you’ll need to do a SELECT INTO to get the next value from the sequence

    CREATE TRIGGER trigger_name
      BEFORE INSERT ON t1
      FOR EACH ROW
    DECLARE
    BEGIN
      IF( :new.id IS NULL )
      THEN
        SELECT t1_id_seq.nextval
          INTO :new.id
          FROM dual;
      END IF;
    END;
    

    Be aware that Oracle sequences are not gap-free. So it is entirely possible that particular values will be skipped for a variety of reasons. Your first insert may have an ID of 10000 and the second may have an ID of 10020 if it’s done minutes, hours, or days later.

    Additionally, be aware that Oracle does not support specifying multiple rows in the VALUES clause as MySQL does. So rather than

    insert into t1 (firstname, lastname) values ('Michael','Jordan'),('Larry','Bird')
    

    you’d need two separate INSERT statements

    insert into t1 (firstname, lastname) values ('Michael','Jordan');
    insert into t1 (firstname, lastname) values ('Larry','Bird');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have never done any Windows coding and I would like to give it
I have never programmed a gadget for Vista or Seven, but I would like
I have a custom dependency property that I would like to use as a
In the first time I have created one Table DEPTS . After that I
I have never seen a way to do this nicely, i would be interested
In SQL Server 2008, is it possible to create a column that can have
I am trying to create a trigger in Oracle. I know sql but i
I have a php script that triggers some magento actions, and I set it
I want to have a database table that keeps data with revision history (like
I have a UITableView that I never want to fall below 1 cell: It's

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.