Oracle 序列

 

 

今天业务说要增加一个序列,给了一条SQL语句:

create sequence seq_t_*** increment by 1 start with 1 maxvalue 999999999;

 

Oracle序列?这么一个对象的最大值是多少呢?

看了看官方文档

Overview of the Sequence Generator

The sequence generator provides a sequential series of numbers. The sequence generator is especially useful in multiuser environments for generating unique sequential numbers without the overhead of disk I/O or transaction locking. For example, assume two users are simultaneously inserting new employee rows into the employees table. By using a sequence to generate unique employee numbers for the employee_id column, neither user has to wait for the other to enter the next available employee number. The sequence automatically generates the correct values for each user.

Therefore, the sequence generator reduces serialization where the statements of two transactions must generate sequential numbers at the same time. By avoiding the serialization that results when multiple users wait for each other to generate and use a sequence number, the sequence generator improves transaction throughput, and a user's wait is considerably shorter.

Sequence numbers are integers of up to 38 digits defined in the database. A sequence definition indicates general information, such as the following:

  • The name of the sequence

  • Whether the sequence ascends or descends

  • The interval between numbers

  • Whether Oracle Database should cache sets of generated sequence numbers in memory

Oracle Database stores the definitions of all sequences for a particular database as rows in a single data dictionary table in the SYSTEM tablespace. Therefore, all sequence definitions are always available, because the SYSTEM tablespace is always online.

Sequence numbers are used by SQL statements that reference the sequence. You can issue a statement to generate a new sequence number or use the current sequence number. After a statement in a user's session generates a sequence number, the particular sequence number is available only to that session. Each user that references a sequence has access to the current sequence number.

Sequence numbers are generated independently of tables. Therefore, the same sequence generator can be used for more than one table. Sequence number generation is useful to generate unique primary keys for your data automatically and to coordinate keys across multiple rows or tables. Individual sequence numbers can be skipped if they were generated and used in a transaction that was ultimately rolled back. Applications can make provisions to catch and reuse these sequence numbers, if desired.

Caution:

If your application can never lose sequence numbers, then you cannot use Oracle Database sequences, and you may choose to store sequence numbers in database tables. Be careful when implementing sequence generators using database tables. Even in a single instance configuration, for a high rate of sequence values generation, a performance overhead is associated with the cost of locking the row that stores the sequence value.

See Also:

 

摘取几个重要的信息点:序列号是一个可以被多个用户共享的数据库对象,可以存在内存中,他的最大值是38位数,我的理解应该就是有上线,最大值38个9那么大,哈哈。

当然也有说到,如果应用程序无法脱离序列这个对象,那么还是不要用序列了。

 

 

 

 

 

 

 

posted @ 2017-02-22 11:40  秋秋哒  阅读(128)  评论(0编辑  收藏  举报