`

Oracle中,何种情况下Sequence被限制使用

阅读更多
  Oracle中,何种情况下Sequence被限制使用

1、在使用Oracle序列的currval和nextval时的限制

创建一个序列
create sequence test_seq
minvalue 1
maxvalue 10000000
start with 1
increment by 1
cache 20;

2、在delete,select,update语句的子查询中不能使用sequence的值

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: 此处不允许序号
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: 此处不允许序号
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: 此处不允许序号

3、在查询视图或物化视图时

SQL> select a.* from test_v a where a.userid<test_seq.currval  ;
select a.* from test_v a where a.userid<test_seq.currval
ORA-02287: 此处不允许序号

4、带有distinct操作符的select语句不能使用

SQL> select distinct a.*,test_seq.currval from test_v a ;
select distinct a.*,test_seq.currval from test_v a
ORA-02287: 此处不允许序号

5、有group by,order by操作的select语句不能使用

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: 此处不允许序号
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: 此处不允许序号

6、有UNION, INTERSECT, MINUS操作符的语句不能使用

SQL> 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;
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: 此处不允许序号
SQL> 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;
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: 此处不允许序号
SQL> 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;
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: 此处不允许序号

7、在select语句中的where子句中

SQL> select  test_jy.* from test_jy where test_id<test_seq.currval;
select  test_jy.* from test_jy where test_id<test_seq.currval
ORA-02287: 此处不允许序号

8、在create table或alter table语句的中default值是不能使用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: 列在此处不允许

9、还有就在check约束中不能使用

本文来源:[url]http://www.55linux.com/oracle/DBA/536.html | 55linux[/url]
分享到:
评论

相关推荐

    oracle中的sequence实现主键增长

    Oracle中的Sequence是数据库管理系统提供的一种机制,用于生成序列化的整数,通常用于主键或唯一标识符,确保数据的唯一性和有序性。在Oracle中,Sequence不同于其他数据库系统的自增字段,例如SQL Server中的`...

    Oracle sequence 重置(失效恢复)

    在Oracle数据库移植过程中,sequence可能失效,本资源可使失效的sequence重新恢复作用

    Oracle创建自增字段方法-ORACLE SEQUENCE的简单介绍

    一旦定义了 SEQUENCE,可以使用 CURRVAL 和 NEXTVAL 来获取当前值和下一个值。CURRVAL 返回当前 SEQUENCE 的值,NEXTVAL 增加 SEQUENCE 的值,然后返回增加后的值。 例如,使用 S_S_DEPART SEQUENCE.insert 一个新...

    oracle中sequence介绍及应用

    oracle中sequence介绍及应用

    oracle 存储过程使用 sequence

    在Oracle中,Sequence则是一种自增序列号生成器,通常用于主键或者唯一标识的生成。在本话题中,我们将深入探讨如何在存储过程中使用Sequence。 首先,理解Sequence的基本概念。Sequence在Oracle中是一个预定义的...

    使用JDeveloper开发WEB应用时同时使用Oracle的sequence和trigger

    在Oracle中,sequence是一种自动递增或递减的数字序列,常用于生成唯一的主键值,避免手动为每条新记录分配ID。创建一个sequence后,你可以通过nextval或currval函数获取序列的下一个或当前值。 Trigger则是数据库...

    分享ORACLE SEQUENCE跳号总结

    在ORACLE数据库中,序列(SEQUENCE)是使用非常频繁的一个数据库对象,但是有时候会遇到序列(SEQUECNE)跳号(skip sequence numbers)的情形,那么在哪些情形下会遇到跳号呢?  事务回滚引起的跳号  不管序列有...

    oracle_sequence.rar_oracle

    在Oracle中,序列(Sequence)是一个非常重要的概念,它主要用于生成唯一的整数序列,常常被用来作为主键值,特别是在插入新记录时自动增加。在本篇文章中,我们将深入探讨Oracle序列的创建、使用以及其在实际应用中...

    生成oracle数据库中的所有sequence的语句

    可以根据oracle数据库中存在的sequence,生成建立语句

    oracle GoldenGate 同步oracle sequence的步骤

    oracle GoldenGate 同步oracle sequence的步骤

    oracle 主键自增 sequence

    ,这样在反复操作时会加快运行速度,但如果遭遇意外情况如当机了或oracle死了,则下次取出的seq值将和上次的不连贯.(如果连不连贯无所谓建议用cache,因为时间就是金钱呀 胡萝卜须 23:20:42 有啊 緣,仯芣妸訁 23:20:57 ...

    让CoolSQL支持Oracle Sequence的GeneratedKey,懂的入

    5. **存储过程**:在某些情况下,你可以创建一个Oracle的存储过程来处理Sequence生成和插入操作,然后在CoolSQL中调用这个存储过程。这种方法将业务逻辑移出客户端,使代码更加整洁。 总的来说,使CoolSQL支持...

    Hibernate Oracle sequence的使用技巧

    本文将详细介绍如何在Hibernate中使用Oracle sequence,以及在使用过程中应注意的一些事项。 首先,我们来看如何为不同的表创建各自的sequence。在Oracle数据库中,你可以通过SQL语句创建一个sequence,例如: ```...

    ORACLE SEQUENCE的简单介绍

    Sql Server 数据库,插入操作时可以设置,自动编号。但是ORACLE 数据库,具有里一个东西SEQUENCE,在这儿介绍

    sequence等同于序列号

    在Oracle数据库中,sequence等同于序列号,每次取的时候sequence会自动增加,一般会作用于需要按序列号排序的地方。 1、Create Sequence (注释:你需要有CREATE SEQUENCE或CREATE ANY SEQUENCE权限) CREATE ...

    Oracle创建自增字段–ORACLE SEQUENCE的简单使用介绍

    先假设有这么一个表: 代码... 在oracle中sequence就是所谓的序列号,每次取的时候它会自动增加,一般用在需要按序列号排序的地方。 1、Create Sequence 你首先要有CREATE SEQUENCE或者CREATE ANY SEQUENCE权限, CREAT

    Oracle、DB2、PostgreSQL之Sequence总结

    Sequence是数据库系统按照一定规则自动增加的数字序列。这个序列一般作为代理主键(因为不会重复),没有其他任何...比如Oracle、DB2、PostgreSQL数据库有Sequence,MySQL、SQL Server、Sybase等数据库没有Sequence。

Global site tag (gtag.js) - Google Analytics