Oracle创建序列及循环自增取值问题

来源:互联网 发布:软件测试吉安 编辑:程序博客网 时间:2024/05/01 01:55

用sys登陆Oracle

SQL> conn sys/root as sysdba;

创建sequence

SQL> create sequence test_seq maxvalue 9 increment by 2 start with 1 cache 2 cycle;

创建对应测试table

SQL> create table test_table(next number,curr number);
插入测试数据(循环执行10次)

SQL> insert into test_table(next,curr) values (test_seq.nextval,test_seq.currval);

取出数据:

SQL> select * from testseq1;

      NEXT       CURR
---------- ----------
         1          1
         3          3
         5          5
         7          7
         9          9
        11         11
        13         13
        15         15
        17         17
        19         19