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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:59:01+00:00 2026-06-08T05:59:01+00:00

For some reason, people in the past have inserted data without using sequence.NEXTVAL. So

  • 0

For some reason, people in the past have inserted data without using sequence.NEXTVAL. So when I go to use sequence.NEXTVAL in order to populate a table, I get a PK violation, since that number is already in use in the table.

How can I update the next value so that it is usable? Right now, I’m just inserting over and over until it’s successful (INSERT INTO tbl (pk) VALUES (sequence.NEXTVAL)), and that syncs up the nextval.

  • 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-08T05:59:03+00:00Added an answer on June 8, 2026 at 5:59 am

    These two procedures let me reset the sequence and reset the sequence based on data in a table (apologies for the coding conventions used by this client):

    CREATE OR REPLACE PROCEDURE SET_SEQ_TO(p_name IN VARCHAR2, p_val IN NUMBER)
    AS
       l_num   NUMBER;
    BEGIN
       EXECUTE IMMEDIATE 'select ' || p_name || '.nextval from dual' INTO l_num;
    
       -- Added check for 0 to avoid "ORA-04002: INCREMENT must be a non-zero integer"
       IF (p_val - l_num - 1) != 0
       THEN
          EXECUTE IMMEDIATE 'alter sequence ' || p_name || ' increment by ' || (p_val - l_num - 1) || ' minvalue 0';
       END IF;
    
       EXECUTE IMMEDIATE 'select ' || p_name || '.nextval from dual' INTO l_num;
    
       EXECUTE IMMEDIATE 'alter sequence ' || p_name || ' increment by 1 ';
    
       DBMS_OUTPUT.put_line('Sequence ' || p_name || ' is now at ' || p_val);
    END;
    
    CREATE OR REPLACE PROCEDURE SET_SEQ_TO_DATA(seq_name IN VARCHAR2, table_name IN VARCHAR2, col_name IN VARCHAR2)
    AS
       nextnum   NUMBER;
    BEGIN
       EXECUTE IMMEDIATE 'SELECT MAX(' || col_name || ') + 1 AS n FROM ' || table_name INTO nextnum;
    
       SET_SEQ_TO(seq_name, nextnum);
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty sure that many people have thought of this, but for some reason
Is there a specific reason why some people put a semicolon after the curly
I have the following code pasted below. For some reason, the response.redirect seems to
I know that is the reason some people don't approve of them, but does
For some reason, I notice that I end up using a lot of finite
My web-app has this secret place only some people are allowed to use. When
For some reason my bot wont private message a % of people on the
For some reason the Joomla docs are not very friendly to people that don't
When using the JDBC for SQLite for some reason Date and Timestamp values are
When going through some of my applications in the past, I have noticed that

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.