在表單增加資料時不需要使用者輸入id值,是通過自增加來實現的
實現方法:
--先建乙個序列號:create sequence autoid
increment by1
start
with
1minvalue
1maxvalue
9999999
--建立乙個觸發器對序列號和觸發器的操作:create trigger trg_bs_company
before insert on bs_company
foreach row
--在一次操作表的語句中,每操作成功一行就會觸發一次;不寫的話,表示是表級觸發器,則無
論操作多少行,都只觸發一次;
begin
select
autoid
.nextval
into
:new
.id
from
dual;--
new是表示將新增的記錄,如果有
old就是將要修改的記錄
--autoid
.nextval
表示序列的下乙個
end;
drop sequence autoid--刪除序列
drop trigger trg_bs_company
;--刪除觸發器
Oracle 主鍵id 實現自增長
建立序列 create sequence t student seq minvalue 1 nomaxvalue start with 1 increment by 1 nocycle nocache 說明 建立索引 create sequence t student seq 索引名稱 minval...
oracle關於ID自增長
1.建立序列 create sequence create sequence innerid minvalue 1 maxvalue 99999999999999 start with 1 increment by 1 cache 20 order 2.innerid.currval 指當前序列 i...
oracle中的ID號如何實現自增長
利用序列產生主鍵值。序列 sequence 是一種可以被多個使用者使用的用於產生一系列唯一數字的資料庫物件。序列定義儲存在資料字典中,通過提供唯一數值的順序表來簡化程式設計工作,可以使用序列自動產生主鍵的鍵值。當乙個序列第一次被查詢呼叫時,它將返回乙個預定值。在隨後的每次查詢中,序列將產生乙個按指定...