Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Get max of sequence value and add next values..

mist123Apr 5 2021

Hi All,
I have a code like below.
SELECT a.*,
ROWNUM seq_num,
Ceil (ROWNUM / 1000) * 10 batch_id
The max of the sequence number is 2034 -- so the batch_id is 20.
I don't want to reload my data again, I just want to insert few records into the existing table.
here I want to start my sequence from 2035 and the batch should be 20 and so on...can you please help me with how to achieve this?
existing data in the table.
select '1010' order_id, 1 seq_num, 10 batch_id from dual
union all
select '2020' order_id,2 seq_num, 10 batch_id from dual
union all
select '3040' order_id, 2034 seq_num, 20 batch_id from dual
new data that needs to be inserted.
select '5010' order_id, 2035 seq_num from dual (seq_num should be 2035)
union all
select '5012' order_id, 2036 from dual
union all
select '5014' order_id, 2037 from dual
Please help me

This post has been answered by Frank Kulash on Apr 5 2021
Jump to Answer
Comments
Post Details
Added on Apr 5 2021
4 comments
3,609 views