Home  >  Article  >  Database  >  How to query the value of the current sequence in oracle

How to query the value of the current sequence in oracle

WBOY
WBOYOriginal
2022-05-30 18:19:0918378browse

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.

How to query the value of the current sequence in oracle

The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.

How to query the value of the current sequence in oracle

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

How to query the value of the current sequence in oracle

The value queried for the first time using nextval is (start with n).

select dept_deptid_seq.nextval from dual

How to query the value of the current sequence in oracle

After that, you can use currval as you like.

select dept_deptid_seq.currval from dual

How to query the value of the current sequence in oracle

When the sequence is queried again, its last_number becomes the next value of the sequence.

How to query the value of the current sequence in oracle

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn