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

  • Home
  • SEARCH
  • 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 8578329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:21:48+00:00 2026-06-11T20:21:48+00:00

I want to make some inserts into a table, using some data from powerbuilder.

  • 0

I want to make some inserts into a table, using some data from powerbuilder. I am a little lost when it comes to using SQL sequences to increment the last known ID.

I know how to find the max ID, but how can I use a sequence to make sure that every new INSERT increments the ID by 1?

So far all I have is how to find my max id:

SELECT MAX(id)
FROM table_name;

EDIT
I am using Oracle for my database

Thanks.

  • 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-11T20:21:49+00:00Added an answer on June 11, 2026 at 8:21 pm

    In oracle, to get the next value in the sequence, you use .nextval.

    Example :

    select my_sequence.nextval from dual;
    

    When you are importing data and let’s say ids till 10000 have been used up already, you could alter your sequence to increment by that number. Since this is DDL, you might have to use Dynamic SQL.

    declare
      l_current_max_value number;
      l_dummy number
    begin
      select max(id)
        into l_current_max_value 
        from my_table;
    
      for i in 1..l_current_max_value loop
        l_dummy := l_current_max_value.nextval; --bouncing the sequence, 
                                                --another option is to recreate it.
      end loop; 
    
    end;
    /
    

    NOTE: THis is asuming your current sequence isn’t used at all. If you are importing data into an existing table with data, it will be more work along the same lines and you need to think about common Ids in both tables.

    EDIT : “how do I assign the current_max_number to the my_sequence”

    Once all the importing is done, you can get the ids using .nextval. Eg.

    create or replace procedure new_product(
      i_sku in number,
      i_name in varchar2(100)
    )
    as
    begin
      insert into new_product (id, sku, name)
      values (product_seq.nextval, i_sku, i_name);
    
      commit;
    end;
    /
    

    or you can get it into a variable for any further processing..

    declare
     l_next_id number;
    begin
     select my_sequence.nextval
       into l_next_id
       from dual;
     --further processing
    end;
    /
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am inserting some data into a MySQL table using CodeIgniter. Because I am
I need to create an SQL query to insert some data into a table
I want to make some C++ program and I'm using function popen here to
I am coding SQL Server 2005 trigger. I want to make some logging during
I need to move some data from a table to a archive table. Now
I'm using a prepared statement to insert some values into my table. Before doing
If a user inserts rows into a table, i would like SQL Server to
I have an activity where i want to to save some measures data into
here is myproblem, i want to make a php function to insert some random
Let's say I want make some of my sources publicly available via my blog

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.