Oracle自動添加列

來源:互聯網
上載者:User

標籤:

Oracle資料庫的表格怎樣才能想MySQL一樣整數主鍵擁有自動增加功能呢?

  前提你得建立一個表 

create table tab{       id number not null primary key,--主鍵           .             .          . }    

  

      然後,得建立一個序列

-- Create sequence create sequence SEQ_tab  ---  SEQ_tab序列的名稱minvalue 1 --輸入最小值maxvalue 99999999999999999999999 --輸入的最大值start with 21increment by 1 --以 1 為單位增加或減少cache 20 --緩衝order; --排序方式

  然後,建立一個觸發器(在你插入一行資料之前觸發)

1 create or replace trigger tab_trig2               before insert on tab3               for each row4         declare5           -- local variables here6         begin7              select seq_customer.nextval into :new.id from dual;8         end tab_trig;

  最後,插入一條資料測試(注意不要往id 欄位(被要求自動添加列的欄位)插)

  

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.