Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle Sequences

I'm using a Sequence to generate an id for me, but I use that sequence from my Java application. So say for example my last Id is 200.

If I add an entry with .sql by by using 201 as an id instead of doing seq.nextval. What would happen when my java application calls seq.nextval? Is sequence smart enough to check the max available number or it will just return 201?

like image 961
ed1t Avatar asked Jun 22 '26 05:06

ed1t


2 Answers

It will just return 201, as the sequence has no idea what the numbers are used for.

Note: It may return, say, 220 if you have specified that the sequence has to cache values for some session (see the Oracle manual about CREATE SEQUENCE for more details)

like image 179
andri Avatar answered Jun 24 '26 20:06

andri


Sequences just provide a way to "select" numbers that auto increment.

You will get 201 because they don't check anything, they just store the last value retrieved and when you query it again, it will return the next value in the sequence.

like image 23
juan Avatar answered Jun 24 '26 20:06

juan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!