In Oracle, you can use the select statement to query the value of the current sequence. The syntax is "select sequence name.currval from dual". currval means returning the value of the current sequence; you must first use nextval to query the value of the next sequence. Only then can this statement be used to query the current sequence value.
The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.
select 序列名.currval from dual; //获取序列的当前值,这个值是可变的。
It should be noted that:
After the database connection is successful, if this sentence is executed for the first time, an exception will be reported and cannot be used.
If it’s not that the word in your statement is spelled incorrectly, it’s because the following SQL statement (select sequence name.nextval from dual;) was not executed first.
That is, first get the current value of the sequence plus the value after the increment. (I don’t know what this is and haven’t studied it yet)
Query the value of the sequence
After the sequence has just been created, you cannot directly query the value of the current sequence. You must First use nextval to query the value of the next sequence, and then use currval to query the value of the current sequence.
Query sequence
select sequence_name ,last_number, min_value,max_value,increment_by from user_sequences
The value queried for the first time using nextval is (start with n).
select dept_deptid_seq.nextval from dual
After that, you can use currval as you like.
select dept_deptid_seq.currval from dual
When the sequence is queried again, its last_number becomes the next value of the sequence.
Recommended tutorial: "Oracle Video Tutorial"
The above is the detailed content of How to query the value of the current sequence in oracle. For more information, please follow other related articles on the PHP Chinese website!