Home > Database > Oracle > body text

How to query the next sequence in oracle

WBOY
Release: 2022-05-24 17:07:06
Original
5249 people have browsed it

In Oracle, you can use the select statement with Nextval to query the next sequence. Nextval returns the initial value for the first time, and the sequence value will be increased each time thereafter, so you can query the next sequence. The syntax is " select sequence name.Nextval from dual".

How to query the next sequence in oracle

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

How to query the next sequence in oracle

select 序列名.Nextval from dual;--生成并获得下一个序列
select 序列名.CURRVAL from dual;--如果与上述语句为同一会话,可以通过此句获得上面生成的序列。
Copy after login

The example is as follows:

How to query the next sequence in oracle

Expand knowledge:

SELECT INR_REQUIRMENT_SQUENCE.CURRVAL FROM dual
Copy after login

--Get the value of the current sequence. The first NEXTVAL returns the initial value;

The subsequent NEXTVAL will automatically increase the INCREMENT BY value you defined, and then return the increased value. . CURRVAL always returns the value of the current sequence, but CURRVAL can be used after the first NEXTVAL initialization, otherwise an error will occur.

A NEXTVAL will increase the value of sequence once, so if you use multiple NEXTVALs in the same statement.

In fact, sequence is a sequence number generator that can automatically generate sequence numbers for rows in the table and generate a set of equally spaced values ​​(type is number). Its main purpose is to generate the primary key value of the table, which can be referenced in the insert statement. Before inserting, obtain the sequence number nextval value and then insert it. You can also check the current value through a query, or increment the sequence to the next value.

How to define a sequence?

create sequence INR_REQUIRMENT_SQUENCE  
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
CACHE 10;
Copy after login

Recommended tutorial: "Oracle Video Tutorial"

The above is the detailed content of How to query the next sequence in oracle. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template