Sequence restrictions in Oracle

Source: Internet
Author: User
Restrictions when using the currval and nextval of the Oracle sequence. The sequence value cannot be used in the delete, select, and update subqueries.

Restrictions when using the currval and nextval of the Oracle sequence. The sequence value cannot be used in the delete, select, and update subqueries.

Limitations when using Oracle sequence currval and nextval

Create a sequence

Create sequence test_seq

Minvalue 1

Max value 10000000

Start with 1

Increment by 1

Cache 20;

Sequence values cannot be used in the delete, select, and update subqueries.

SQL> delete from test_jy where test_id <(select test_seq.currval from dual );

Delete from test_jy where test_id <(select test_seq.currval from dual)

ORA-02287: serial numbers are not allowed here

SQL> select * from test_jy where test_id <(select test_seq.currval from dual );

Select * from test_jy where test_id <(select test_seq.currval from dual)

ORA-02287: serial numbers are not allowed here

SQL> update test_jy set test_id = 0 where test_id <(select test_seq.currval from dual );

Update test_jy set test_id = 0 where test_id <(select test_seq.currval from dual)

ORA-02287: serial numbers are not allowed here

When querying a view or Materialized View

SQL> select a. * from test_v a where a. userid

Select a. * from test_v a where a. userid < p><>

ORA-02287: serial numbers are not allowed here

Select statements with distinct operators cannot be used.

SQL> select distinct a. *, test_seq.currval from test_v;

Select distinct a. *, test_seq.currval from test_v

ORA-02287: serial numbers are not allowed here

Select statements with group by and order by operations cannot be used.

SQL> select test_jy. *, test_seq.currval from test_jy group by test_jy.test_id;

Select test_jy. *, test_seq.currval from test_jy group by test_jy.test_id

ORA-02287: serial numbers are not allowed here

SQL> select test_jy. *, test_seq.currval from test_jy order by test_jy.test_id;

Select test_jy. *, test_seq.currval from test_jy order by test_jy.test_id

ORA-02287: serial numbers are not allowed here

Statements with UNION, INTERSECT, and MINUS operators cannot be used.

SQL> select test_jy. *, test_seq.currval from test_jy where test_id = 1

2 union

3 select test_jy. *, test_seq.currval from test_jy where test_id = 2;

Select test_jy. *, test_seq.currval from test_jy where test_id = 1

Union

Select test_jy. *, test_seq.currval from test_jy where test_id = 2

ORA-02287: serial numbers are not allowed here

SQL> select test_jy. *, test_seq.currval from test_jy where test_id = 1

2 intersect

3 select test_jy. *, test_seq.currval from test_jy where test_id = 2;

Select test_jy. *, test_seq.currval from test_jy where test_id = 1

Intersect

Select test_jy. *, test_seq.currval from test_jy where test_id = 2

ORA-02287: serial numbers are not allowed here

SQL> select test_jy. *, test_seq.currval from test_jy where test_id = 1

2 minus

3 select test_jy. *, test_seq.currval from test_jy where test_id = 2;

Select test_jy. *, test_seq.currval from test_jy where test_id = 1

Minus

Select test_jy. *, test_seq.currval from test_jy where test_id = 2

ORA-02287: serial numbers are not allowed here

In the where clause of the select statement

SQL> select test_jy. * from test_jy where test_id < p><>

Select test_jy. * from test_jy where test_id < p><>

ORA-02287: serial numbers are not allowed here

In the create table or alter table statement, the default value cannot use sequence.

SQL> alter table test_jy modify test_id number (20) default test_seq.currval;

Alter table test_jy modify test_id number (20) default test_seq.currval

ORA-00984: The column is not allowed here

Also, it cannot be used in the check constraint.

,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.