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.
In oracle, to get the next value in the sequence, you use .nextval.
Example :
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.
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.
Once all the importing is done, you can get the ids using .nextval. Eg.
or you can get it into a variable for any further processing..