Oracle建立Sequence時Order/NoOrder選項____Oracle

來源:互聯網
上載者:User
問題

Oracle建立Sequence時會有Order/NoOrder兩個選項,那麼到底什麼情境用到Order,什麼情境又用到NoOrder呢。 官方文檔

ORDER     guarantees that sequence numbers are generated in order of request.     You may want to use this option if you are using the sequence     numbers as timestamps. Guaranteeing order is usually not important     for sequences used to generate primary keys. NOORDER     does not guarantee sequence numbers are generated in order of     request.     If you omit both the ORDER and NOORDER options, Oracle chooses     NOORDER by default. Note that the ORDER option is only necessary to     guarantee ordered generation if you are using Oracle with the     Parallel Server option in parallel mode. If you are using exclusive     mode, sequence numbers are always generated in order. 
分析

Order:

保證序號按請求順序產生。如果想以序號作為timestamp(時間戳記)類型的話,可以採用該選項。對於將序列用於產生主鍵來說,約定順序通常並不重要。

NOORDER:
此選項跟Order相對應,並不按照請求的順序進行產生。 舉例

雙CPU對同一個oracle DB 中的 ABC sequence申請序號時, 這時就有兩個請求A和B,假設A請求在前B在後, 現在 ABC序列中的值為9。 如果添加了ORDER選項,那麼一定是A請求到9, B請求到10。但如果沒有添加此選項,則有可能B請求到9, A請求到 10。 總結

無論使用哪個選項,sequence中產生的資料都是唯一的。因此,我們可以得出結論,在用sequence中的資料作為ID時,無論選擇哪個選項都能確保ID的唯一性。但如果,用sequence中的資料作為時間戳記時,則需要使用Order選項,確保先到的請求時鐘排序在前面。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.