-- 1、在plsql下先建立乙個專用的使用者
-- create the user
create user user1
identified by \"user1\"
default tablespace users
temporary tablespace temp
profile default;
-- grant/revoke role privileges
grant dba to user1;
-- grant/revoke system privileges
grant unlimited tablespace to user1;
------------------------------------
------------------------------------
-- 建表
create table aaa (
oid number not null,
type number(3)
);以下部分處理自增序列問題
--自增序列
--第一步:建乙個佇列
create sequenceaaa_oid_sequence
increment by 1 --每次加幾個
start with 1 --從1開始計數
nomaxvalue --不設定最大值
nocycle --一直累加,不迴圈
nocache ;
--第二步:建立觸發器
create or replace triggeraaa_oid_trigger
before insert onaaafor each row
declare
next_id number;
begin
--get the next id number from the sequence
selectaaa_oid_sequence.nextval into next_id from dual;
--use the sequence number as the primarykey
--for there cord being inserted.
:new.oid:=next_id;
end;
測試:insert into aaa (type) values (2);
select * from aaa;
ORACLE建立自增序列
步驟 1.建立序列 2.建立觸發器。語法解析 create sequence tb code sequence minvalue 1 maxvalue 999999999999999999999999999 start with 11 increment by 1 cache 10 create o...
Oracle 建立序列自增
oracle不像sql server 有關鍵字identity直接可插入資料時自增 實現oracle 自增列第一步,建立乙個sequence。create sequence tempinfo seq increment by 1 start with 1 minvalue 1 maxvalue 99...
oracle建立自增序列
create sequence user sequence increment by 1 自增1 start with 2 從2開始 nomaxvalue 沒有最大值 nocycle 不迴圈 cache 10 快取10個 select user sequence.currval from dual ...