如何查找Oracle序列的起始值

时间:2015-05-07 19:54:30

标签: oracle sequence

我想获得Oracle序列的起始值。我使用命令grid_3 <- rbind(setNames(do.call(what = expand.grid,args = list(data_list[1:3],stringsAsFactors = FALSE)),nm = c("V1","V2","V3")), setNames(do.call(what = expand.grid,args = list(data_list[2:4],stringsAsFactors = FALSE)),nm = c("V1","V2","V3")), setNames(do.call(what = expand.grid,args = list(data_list[3:5],stringsAsFactors = FALSE)),nm = c("V1","V2","V3")), setNames(do.call(what = expand.grid,args = list(data_list[4:6],stringsAsFactors = FALSE)),nm = c("V1","V2","V3"))) 。但是没有起始值的列。有没有简单的方法来获得起始值?

3 个答案:

答案 0 :(得分:0)

抱歉,一般情况下你不能这样做。看:

SQL> create sequence s start with 100 increment by -10 minvalue 0 maxvalue 1000 cycle;

Sequence created.

SQL> select sequence_name, min_value, max_value, increment_by, last_number 
   2 from user_sequences where sequence_name = 'S';

SEQUENCE_N  MIN_VALUE  MAX_VALUE INCREMENT_BY LAST_NUMBER                       
---------- ---------- ---------- ------------ -----------                       
S                   0       1000          -10         100                       

SQL> select s.nextval from dual connect by level <= 5;

   NEXTVAL                                                                      
----------                                                                      
       100                                                                      
        90                                                                      
        80                                                                      
        70                                                                      
        60                                                                      

SQL> select sequence_name, min_value, max_value, increment_by, last_number 
   2 from user_sequences where sequence_name = 'S';

SEQUENCE_N  MIN_VALUE  MAX_VALUE INCREMENT_BY LAST_NUMBER                       
---------- ---------- ---------- ------------ -----------                       
S                   0       1000          -10         -10                       

答案 1 :(得分:0)

也许不是尝试从序列中读取起始值,而是可以从它生成的数字推断它。 Min()或Max()表示降序,从中选择的列中选择。

答案 2 :(得分:0)

您还可以使用ddl命令查找start with value,即用于创建序列的语句。

SQL>   SELECT dbms_metadata.get_ddl('SEQUENCE','GEN_VALUES') FROM dual;

DBMS_METADATA.GET_DDL('SEQUENCE','GEN_VALUES')
--------------------------------------------------------------------------------

   CREATE SEQUENCE  "SCOTT"."GEN_VALUES"  MINVALUE 1000 MAXVALUE 1000000 INCREME
NT BY 1 START WITH 1000 CACHE 20 NOORDER  NOCYCLE