oracle 資料庫中的序列

來源:互聯網
上載者:User

標籤:ora   tar   儲存   sql   create   body   建立表   start   sequence   

  序列是什麼,通俗點說,序列就是按照一定順序進行排列,序列會自動給你遞增,產生唯一的序號;

    oracle資料庫不同於sqlServer資料庫,oracle資料庫中是沒有自增長列,使用的是sequence序列;

 ==== 建立序列  

  create  sequence  emp_sequence               --    (序列名) 

       increment     by  1                                      --  (每次增長的數)

        start with  1                                                 --    (開始值) 

        nomaxvalue                                                --     (沒有上限值) 

        nocycle                                                       --     (不迴圈,遞增) 

        nocache                                                      --   (緩衝) 

 

==== 如何使用序列 (一般用於在主鍵列或者是唯一的自增列) 

    --建立表

       create table user ( userId  number(10)    primary key, userName  varchar2(30))
   --在表使用序列
        insert  into  user (userId, userName) values(emp_sequence.nextval, "張三" )
 ====1、需要注意的一般常使用nocache 這可以防止出現跳號的情況,cache 10  使用會將10個序號儲存在緩衝中,這樣會提高效率,如果出現異常情況(斷電或斷網等等)
會出現跳號的現象;2、在使用currval 前需要先初始化(先執行nextval)
例如: select emp_sequence.nextval form dual;  --- 第一次返回的初始化的序號
select  emp_sequence.currval form dual;   ---  查詢當前的序列

oracle 資料庫中的序列

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.