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.
,