oracle sequence語法

wisdomone1發表於2010-06-27

SQL> create sequence seq_1 start with 1 increment by 1 nomaxvalue;

Sequence created.

SQL> alter sequence seq_1 cache 1000;

Sequence altered.

SQL> alter sequence seq_1 order;

Sequence altered.

SQL> desc user_sequences;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 SEQUENCE_NAME                             NOT NULL VARCHAR2(30)
 MIN_VALUE                                          NUMBER
 MAX_VALUE                                          NUMBER
 INCREMENT_BY                              NOT NULL NUMBER
 CYCLE_FLAG                                         VARCHAR2(1)
 ORDER_FLAG                                         VARCHAR2(1)
 CACHE_SIZE                                NOT NULL NUMBER
 LAST_NUMBER                               NOT NULL NUMBER

SQL> select sequence_name,min_value,max_value,increment_by,cycle_flag,last_number from user_sequences;

SEQUENCE_NAME                   MIN_VALUE  MAX_VALUE INCREMENT_BY C LAST_NUMBER
------------------------------ ---------- ---------- ------------ - -----------
SEQ_1                                   1 1.0000E+27            1 N           1

SQL> alter sequence seq_1 cycle;

Sequence altered.

SQL> select sequence_name,min_value,max_value,increment_by,cycle_flag,last_number from user_sequences;

SEQUENCE_NAME                   MIN_VALUE  MAX_VALUE INCREMENT_BY C LAST_NUMBER
------------------------------ ---------- ---------- ------------ - -----------
SEQ_1                                   1 1.0000E+27            1 Y           1

SQL> select seq_1.currval from dual;
select seq_1.currval from dual
       *
ERROR at line 1:
ORA-08002: sequence SEQ_1.CURRVAL is not yet defined in this session


SQL> select seq_1.nextval from dual;

   NEXTVAL
----------
         1

SQL> select seq_1.currval from dual;

   CURRVAL
----------
         1

SQL>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-666443/,如需轉載,請註明出處,否則將追究法律責任。

相關文章