Skip to main content
1-Visitor
April 21, 2017
Question

How to loop SQL "select WTKEY_SEQ.nextval from dual"

  • April 21, 2017
  • 1 reply
  • 2376 views

Hi guys,

In order to solve a problem of method server start, I have to do the request:

select WTKEY_SEQ.nextval from dual


I have to do it until its value reaches 163553 but now it is only 139082. Each time I do the request, the value increments of 1.


I don't know very much about SQL and I would like to know if there is syntax to make a loop of this request until it reaches the correct value.


Thank you very much.


Regards,

Florent

1 reply

13-Aquamarine
April 27, 2017

Rather than looping the statement, it would be easier to just change the increment value for the sequence. The statement to change the increment value is:

Alter sequence WTKEY_SEQ increment by <New Increment Value>;

Just replace '<New Increment Value>' with the difference between the current sequence value and the value you want the sequence to be. After changing the increment value, then you just need to run 'select WTKEY_SEQ.nextval from dual' once, and it will increment to your target value. Afterward, make sure to set the increment value back to 1, by running:
Alter sequence WTKEY_SEQ increment by 1;