Oracle Sequence brief introduction

zhaozj2021-02-16  72

Oracle Sequence's brief introduction comments from: http://www.fanqiang.com May 14, 2002 19:35 in Oracle Sequence is the so-called serial number, it will automatically increase each time it is taken, generally used in need The serial number is sorted. 1. Create sequence, you must first have create sequence or create any sequence, create sequence emp_sequence increment by 1 - Add a few Start With 1 - start counting from 1 NomaxValue - Do not set the maximum NOCYCLE - have been accumulated , not cycle CACHE 10; Once defined emp_sequence, you can use CURRVAL, NEXTVAL CURRVAL = the current value of the sequence NEXTVAL = return value added sequence, and returns the value of such sequence: emp_sequence.CURRVAL emp_sequence.NEXTVAL may be used where the sequence: - Does not include subqueries, Snapshot, View SELECT statement - Insert statements - NSERT statement VALUES - UPDATE SET can be seen in the SET: INSERT INTO EMP VALUES (Empseq.NextVal, 'Lewis',' Clerk ', NULL, 20); SELECT Empseq.Currval from Dual; But pay attention to: - The first nextVal returned to the initial value; subsequent nextVal will automatically add your deframent BY value, Then return to the increased value. CURRVAL always returns the value of the current sequence, but after the first nextVal initialization, you can use Currval, otherwise it will be wrong. NextVal will increase the value of Sequence, so if you use multiple nextVal in the same statement, its value is different. understand? - If you specify a cache value, Oracle can place some Sequence in memory, so almost. After the cache is taken, Oracle automatically takes a group to cache. Using Cache may be jumped, such as the database suddenly unputdown abort, the sequence in Cache will be lost. So you can prevent this when you Create Sequence will use Nocache. 2, alter sequence you or the sequence's Owner, or ALTER Any Sequence permissions can change Sequence. You can Alter All Sequence parameters other than START. If you want to change the start value, you must re-create. Alter sequence Example ALTER SEQUENCE EMP_SEQUENCE INCREMENT BY 10 MaxValue 10000 CYCLE - Getween 10000 Start Nocache from the header; Impact Sequence initialization parameters: sequence_cache_entries = Set the number of sequence by cache at the same time. You can very simple Drop Sequence Drop Sequence Order_seq;

转载请注明原文地址:https://www.9cbs.com/read-16659.html

New Post(0)