- 浏览: 493828 次
- 性别:
- 来自: xiamen
文章分类
最新评论
-
陈乐鹏:
你这个下载要怎么玩?我这里老提示未安装!
[转]使用ScriptX控件进行Web打印总结 -
zqb666kkk:
博主有示例代码吗
cxf ws-security 加密和签名的实现 -
mclin0704:
你好,请问WSDL2Java 可以用java实现吗?
Java2WSDL之java实现 -
hubiao0629:
楼主,这个文件会有不兼容的问题把。
mysql5忘记密码后的处理方法 -
zhaoyubetter:
OK,可以试试!多谢楼主
后台管理界面收集
Oracle Sequences
Oracle Sequences |
||
Version 10.2 |
General | |
Dependent Objects |
seq$ user_sequences all_sequences dba_sequences seq |
Related System Privileges |
create sequence create any sequence alter any sequence drop any sequence select any sequence |
NOTE : The alternative to sequences used in other RDBMS products is autonumbering and keeping the current number in a table. Both of these other methods demand serialization as they can only dispense one number at a time. |
Table example: CREATE TABLE seqnum ( next_number NUMBER(1); 1. Lock the seqnum table for your transaction 2. SELECT next_number FROM seqnum; 3. UPDATE seqnum SET next_number=next_number+1; 4. Unlock the seqnum table for the next transation |
Tables For Sequence Demos |
CREATE TABLE campus_site ( site_id NUMBER(4), organization_name VARCHAR2(40), campus_name VARCHAR2(30), address_id NUMBER(10)) TABLESPACE data_sml; CREATE TABLE division ( division_id NUMBER(5), site_id NUMBER(4), division_name VARCHAR2(40), address_id NUMBER(10)) TABLESPACE data_sml; CREATE TABLE department ( department_id NUMBER(5), division_id NUMBER(5), department_name VARCHAR2(40), address_id NUMBER(10)) TABLESPACE data_sml; CREATE TABLE seq_test ( test NUMBER(10)) TABLESPACE data_sml; |
Create Sequence | |
Full Create Sequence Syntax |
CREATE SEQUENCE <seq_name> INCREMENT BY <integer> START WITH <integer> MAXVALUE <integer> / NOMAXVALUE MINVALUE <integer> / NOMINVALUE CYCLE / NOCYCLE CACHE <#> / NOCACHE ORDER / NOORDER; |
Create Sequence Simplest Form | CREATE SEQUENCE <sequence_name>; |
CREATE SEQUENCE
seq_campus_site_id; SELECT seq_campus_site_id.NEXTVAL FROM dual; / / |
|
Simple Autonumber With Sequence |
INSERT INTO <table_name> (<column_name>) VALUES (<sequence_name>.NEXTVAL); |
INSERT INTO campus_site (site_id, organization_name, campus_name) VALUES (seq_campus_site_id.NEXTVAL ,'Univ. of Washington','Main Seattle'); SELECT * FROM campus_site; INSERT INTO campus_site (site_id, organization_name, campus_name) VALUES (seq_campus_site_id.NEXTVAL , 'Univ. of Washington', 'Bothell'); SELECT * FROM campus_site; |
|
Simple Autonumber With Sequence Into Two Tables |
INSERT INTO <table_name> (<column_name>) VALUES (<sequence_name>.CURRVAL); |
CREATE SEQUENCE seq_division_id; INSERT INTO campus_site (site_id, organization_name, campus_name) VALUES (seq_division_id.NEXTVAL, 'Univ. of Washington', 'Tacoma'); INSERT INTO division (division_id, site_id, division_name) VALUES (seq_division_id.NEXTVAL, seq_campus_site_id.CURRVAL , 'Engineering'); SELECT * FROM campus_site; SELECT * FROM division; |
|
Simple Transaction Number For Audit Demoing START WITH and a caution with CURRVAL | CREATE SEQUENCE <sequence_name> START WITH <integer>; |
CREATE SEQUENCE seq_audit_tx
START WITH
297
; INSERT INTO campus_site (site_id, organization_name, campus_name) VALUES (seq_audit_tx.NEXTVAL, 'Univ. of Washington', 'Everett'); INSERT INTO division (division_id, site_id, division_name) VALUES (seq_audit_tx.NEXTVAL, seq_audit_tx.CURRVAL, 'Science'); INSERT INTO department (department_id, division_id, department_name) VALUES (seq_audit_tx.NEXTVAL, seq_audit_tx.CURRVAL, 'Astronomy'); SELECT * FROM campus_site; SELECT * FROM division; SELECT * FROM department; ROLLBACK; INSERT INTO campus_site (site_id, organization_name, campus_name) VALUES (seq_audit_tx.NEXTVAL, 'Univ. of Washington', 'Everett'); INSERT INTO division (site_id, division_id, division_name) VALUES (seq_audit_tx.CURRVAL, seq_audit_tx.NEXTVAL, 'Science'); INSERT INTO department (division_id, department_id, department_name) VALUES (seq_audit_tx.CURRVAL, seq_audit_tx.NEXTVAL, 'Astronomy'); SELECT * FROM campus_site; SELECT * FROM division; SELECT * FROM department; |
|
INCREMENT BY | CREATE SEQUENCE <sequence_name> INCREMENT BY <positive integer>; |
CREATE SEQUENCE seq_inc_by_two INCREMENT BY
2; INSERT INTO seq_test VALUES (seq_inc_by_two.NEXTVAL); / / SELECT * FROM seq_test; CREATE SEQUENCE seq_inc_by_ten INCREMENT BY 10; INSERT INTO seq_test VALUES (seq_inc_by_ten.NEXTVAL); / / SELECT * FROM seq_test; ALTER TABLE seq_test ADD test2 NUMBER(10); desc seq_test INSERT INTO seq_test (test, test2) VALUES (seq_inc_by_ten.NEXTVAL, seq_inc_by_ten.NEXTVAL); SELECT * FROM seq_test; INSERT INTO seq_test (test, test2) VALUES (seq_inc_by_ten.NEXTVAL, seq_inc_by_ten.CURRVAL); SELECT * FROM seq_test; |
|
Reverse DECREMENT BY |
CREATE SEQUENCE <sequence_name> MAX VALUE <integer value> INCREMENT BY <negative integer>; |
CREATE SEQUENCE seq_reverse INCREMENT BY -
5; ALTER TABLE seq_test DROP COLUMN test2; INSERT INTO seq_test VALUES (seq_reverse.NEXTVAL); / / / SELECT * FROM seq_test; DROP SEQUENCE seq_reverse; CREATE SEQUENCE seq_reverse MAXVALUE 150 START WITH 150 INCREMENT BY - 5; INSERT INTO seq_test VALUES (seq_reverse.NEXTVAL); / / / SELECT * FROM seq_test; |
|
MAXVALUE Demo |
CREATE SEQUENCE <sequence_name> START WITH <integer> MAXVALUE <integer>; |
CREATE SEQUENCE seq_maxval START WITH
1 MAXVALUE
5; INSERT INTO seq_test VALUES (seq_maxval.NEXTVAL); / / / SELECT * FROM seq_test; INSERT INTO seq_test VALUES (seq_maxval.NEXTVAL); SELECT * FROM seq_test; INSERT INTO seq_test VALUES (seq_maxval.NEXTVAL); |
|
CYCLE Demo |
CREATE SEQUENCE <sequence_name> START WITH <integer> MAXVALUE <integer> CYCLE; |
CREATE SEQUENCE seq_cycle START WITH 1 MAXVALUE 5 CYCLE
; -- default cache is 20 CREATE SEQUENCE seq_cycle START WITH 1 MAXVALUE 5 CYCLE CACHE 4; TRUNCATE TABLE seq_test; INSERT INTO seq_test VALUES (seq_cycle.NEXTVAL); / / / / / / SELECT * FROM seq_test; |
|
CACHE Demo | CREATE SEQUENCE <sequence_name> CACHE <integer>; |
CREATE SEQUENCE seq_cache CACHE
100; SELECT sequence_name, last_number FROM user_sequences; SELECT seq_cache.NEXTVAL FROM dual; SELECT sequence_name, last_number FROM user_sequences; SELECT seq_cache.NEXTVAL FROM dual; / SELECT sequence_name, last_number FROM user_sequences; conn / as sysdba shutdown abort; startup conn uwclass/uwclass SELECT sequence_name, last_number FROM user_sequences; SELECT seq_cache.NEXTVAL FROM dual; |
|
ORDER Demo | CREATE SEQUENCE <sequence_name> START WITH 1 ORDER; |
CREATE SEQUENCE seq_order START WITH 1 ORDER ; | |
Alter Sequence | |
Change Increment | ALTER SEQUENCE <sequence_name> INCREMENT BY <integer>; |
ALTER SEQUENCE seq_inc_by_ten INCREMENT BY 20; | |
Change Max Value | ALTER SEQUENCE <sequence_name> MAX VALUE <integer> |
ALTER SEQUENCE seq_maxval MAXVALUE 10; | |
Change Cycle | ALTER SEQUENCE <sequence_name> <CYCLE | NOCYCLE> |
ALTER SEQUENCE seq_cycle NOCYCLE ; | |
Change Cache | ALTER SEQUENCE <sequence_name> CACHE <integer> | NOCACHE |
ALTER SEQUENCE seq_cache NOCACHE ; | |
Change Order | ALTER SEQUENCE <sequence_name> <ORDER | NOORDER> |
ALTER SEQUENCE seq_order NOORDER ; | |
Drop Sequence | |
Drop Sequence | DROP SEQUENCE <sequence_name>; |
DROP SEQUENCE seq_cache; | |
Sequence Resets | |
By
finding out the current value of the sequence and altering the
increment by to be negative that number and selecting the sequence once
-- the sequence can be reset to 0. If any session attempts to use the sequence while this is happening an ORA-08004 error will be generated. |
CREATE SEQUENCE seq; SELECT seq.NEXTVAL FROM dual; SELECT seq.NEXTVAL FROM dual; SELECT seq.NEXTVAL FROM dual; COLUMN S new_val inc ; SELECT seq.NEXTVAL S FROM dual; ALTER SEQUENCE seq INCREMENT BY -&inc MINVALUE 0; SELECT seq.NEXTVAL S FROM dual; ALTER SEQUENCE seq increment by 1; SELECT seq.NEXTVAL FROM dual; / / |
Stored Procedure Method |
CREATE OR REPLACE PROCEDURE reset_sequence ( seq_name IN VARCHAR2, startvalue IN PLS_INTEGER) AS cval INTEGER; inc_by VARCHAR2(25); BEGIN EXECUTE IMMEDIATE 'ALTER SEQUENCE ' ||seq_name||' MINVALUE 0'; EXECUTE IMMEDIATE 'SELECT ' ||seq_name ||'.NEXTVAL FROM dual' INTO cval; cval := cval - startvalue + 1; IF cval < 0 THEN inc_by := ' INCREMENT BY '; cval:= ABS(cval); ELSE inc_by := ' INCREMENT BY -'; END IF; EXECUTE IMMEDIATE 'ALTER SEQUENCE ' || seq_name || inc_by || cval; EXECUTE IMMEDIATE 'SELECT ' ||seq_name ||'.NEXTVAL FROM dual' INTO cval; EXECUTE IMMEDIATE 'ALTER SEQUENCE ' || seq_name || ' INCREMENT BY 1'; END reset_sequence; / |
Sequence Related Queries | |
Last Number Selected From Sequence |
SELECT sequence_name, last_number FROM user_sequences; |
Next Number From Sequence |
SELECT sequence_name, (last_number + increment_by) NEXT_VALUE FROM user_sequences; |
Related Topics
来自:雪迎的Blog
另外记录下一个地址: http://www.w3school.com.cn/sql/sql_insert.asp
发表评论
-
最新县及县以上行政区划代码(截止2014年10月31日)SQL
2015-09-17 15:32 894最新县及县以上行政区划代码(截止2014年10月31日) ... -
postgresql bat 备份sql
2013-02-26 11:03 2193@echo off e: cd E:\Pos ... -
postgreSQL 实现show create table
2013-02-26 10:40 2903在mysql 中show create table 可以直 ... -
DatabaseMetaData getExportedKey() 无法获取信息
2012-03-14 17:26 1188在jdbc DatabaseMetaData.getExpo ... -
Column 'IS_AUTOINCREMENT' not found
2012-03-14 10:41 2469java.sql.SQLException: Column ' ... -
数据同步给第三方系统的方案探索
2011-05-20 17:16 1461本文来自:http://blogjava.net/amigox ... -
error:ids for this class must be manually assigned before calling save():
2011-04-28 14:35 2776引用一篇文章 来自:MeChecksV org.h ... -
如何使用Oracle SQLDeveloper 中连接MS SQLServer和MySQL数据库
2011-03-17 15:02 1722一、连接至MySQL数据库 1.下载mysql的jd ... -
mysql5忘记密码后的处理方法
2011-03-17 10:54 1906今天想到用MySQL,突然发现忘记MySQL的root密码了, ... -
mysql 编程语言参考
2010-09-29 13:00 1051由于内部比较多,这里就不贴了 可以参考以下页面: m ... -
mysql 实现excel 小数点后面自动请零
2010-09-29 12:44 1774场景:单价的处理 ... -
SQL 判断列是否汉字
2009-03-16 16:15 2619select * from 表名 where ascii( ... -
MySQL常用维护管理工具
2009-03-05 14:29 1442MySQL 是一个非常流行 ... -
MySQL:Linux下自动备份数据库的shell脚本
2009-03-04 16:10 2246Linux 服务器上的程序每天都在更新 MySQL 数据库,于 ... -
MySQL数据库和备份与恢复
2009-03-04 16:08 941在数据库表丢失或损坏 ... -
实现MySQL数据库双机热备份
2009-03-04 16:00 27151、MySQL数据库没有增量备份的机制,当数据量太大的时候备 ... -
TOAD 文档(中英文)
2008-12-31 14:43 1641以前很久之前有同事给我一份toad中文文档,但不知道放那里了, ... -
SQL 语句通过标识符 进行substring (不固定长度Substring)
2008-07-10 19:11 2039今天要对一个字段截取字符,可以不固定长度,所以后来G了下 ...
相关推荐
一、课程用到的软件:oracle 11g 二、课程目标: 1. 为有意从事oracle dba工作人员提供学习...第十六讲:oracle sequences管理 第十七讲:oracle 触发器管理 第十八讲:oracle 用户管理 第十九讲:oracle 安装部署管理
3. **数据库对象**:Oracle数据库包含多种对象,如表(Tables)、视图(Views)、索引(Indexes)、序列(Sequences)、存储过程(Stored Procedures)和触发器(Triggers)。它们是数据库应用的基础,满足不同的...
4. **序列**:Oracle数据库中的序列(Sequences)是一种自动增长的数字序列,常用于生成唯一标识符,如主键。序列可以确保在多用户环境下数据的一致性和完整性。例如,可以创建一个名为emp_id_seq的序列,为新插入的...
接下来,需要创建一个序列(Sequences)来生成唯一标识符。在 Oracle 数据库中,序列是一种特殊的数据库对象,用于生成唯一的数字标识符。创建序列的 SQL 语句如下: ``` CREATE SEQUENCE SEQ_EXCELFILE_LINE ...
7. DBA_SEQUENCES:该数据字典包含了关于数据库序列的信息,如序列名称、序列类型等。 8. DBA_DB_LINKS:该数据字典包含了关于数据库链路的信息,如链路名称、链路类型等。 9. DBA_CONSTRAINTS:该数据字典包含了...
通过dba_sequences视图,可以查询序列的基本信息,包括序列名称、序列类型、创建日期等信息。 视图管理 视图是Oracle数据库中的一种虚拟表,用于提供数据的 논리试图。视图管理是Oracle数据库管理系统的重要组件,...
这些视图家族包括 COL_PRIVS、EXTENTS、INDEXES、IND_COLUMNS、OBJECTS、ROLE_PRIVS、SEGMENTS、SEQUENCES、SOURCE、SYNONYMS、SYS_PRIVS、TAB_COLUMNS、TAB_PRIVS、TABLES、TRIGGERS、USERS 和 VIEWS 等。...
模式对象是指存在于数据库中的数据结构,例如表(tables)、视图(views)、索引(indexes)、序列(sequences)和同义词(synonyms)。这些对象代表了数据存储和组织的方式,对于管理数据库内容至关重要。 表是最...
数据字典中还包括`all_tables`、`all_indexes`、`all_sequences`、`all_constraints`等视图,可以帮助用户查询表、索引、序列和约束的详细信息。通过熟练使用这些视图,可以更高效地管理和监控Oracle数据库。 总之...
ViBe算法,全称为"ViBe: A Universal Background Subtraction Algorithm for Video Sequences",是一篇发表于2011年的论文中介绍的通用背景减除算法。由Hanzi Wang和David Suter撰写,发表于《IEEE Transactions on ...
在Oracle数据库中,序列(Sequences)是一种特殊的数据类型,用于生成唯一的整数序列,通常用于创建自动递增的主键。序列对于大型系统来说非常重要,因为它们可以确保数据的一致性和完整性。以下是对Oracle序列的...
FROM user_sequences a, user_constraints b WHERE SUBSTR(a.sequence_name, 5, 100) = b.table_name AND b.constraint_type = 'P' ) LOOP SELECT func_getseq(cur.table_name) INTO max1 FROM DUAL; EXECUTE ...
### PowerDesigner 创建 Oracle 数据库表并设置主键自动增长 #### 一、PowerDesigner与Oracle数据库集成概述 PowerDesigner是一款强大的数据库设计工具,它能够帮助开发者进行数据建模、概念设计以及物理数据库的...
以下是对给定文件中涉及的一些Oracle 19c知识点的详细解释: 1. **删除表(DROP TABLE)的影响**: 在Oracle数据库中,当你执行`DROP TABLE`命令时,会删除指定的表及其相关的某些对象。在问题1中提到的场景,当...
Oracle自增长主键自动生成类 public static int nextID String table { if table null return 1; table table toLowerCase ; String strKey table; if sequences containsKey strKey { ...
- **查询序列**:`select * from user_sequences;` ### 6. 元数据管理 - **注释管理**:可以使用`COMMENT ON TABLE`或`COMMENT ON COLUMN`命令来添加或修改表或列的注释。 - **描述表结构**:`DESC aa10;`用于描述...
Oracle元数据是数据库管理系统的核心组成部分,它记录了数据库中所有对象的结构、属性以及相互...而文档"Oracle 元数据表.docx"应该会提供更具体的查询示例和详细解释,帮助读者更好地理解和应用这些元数据查询技巧。
- **DBA_SEQUENCES/ALL_SEQUENCES/USER_SEQUENCES**:提供关于序列的信息,包括序列名称、当前值、增量等。 5. **同义词** - **DBA_SYNONYMS/ALL_SYNONYMS/USER_SYNONYMS**:提供关于同义词的信息,包括同义词名称...
- 探索序列(Sequences)的用途,如何生成自动递增的数字。 5. **安全性与权限**: - 管理用户和角色,理解权限(Privileges)和角色(Roles)的分配。 - 学习如何设置表和列的权限,控制数据访问。 - 掌握审计...
- **`SELECT * FROM dba_sequences;`**:显示所有序列的详细信息,序列常用于自动增长的唯一标识符。 ### 七、视图 - **`SELECT * FROM dba_views;`** 和 **`SELECT * FROM all_views;`**:分别列出所有视图和当前...