Oracle ID 自增代碼的詳細介紹
作者:佚名
Oracle ID 自增是一種新生的語言,我們可以看到很多的書籍和網上的相關資料對其的實際操作步驟都有詳細的介紹。本文章就是對Oracle ID 自增在一些資料中很少見的idea
本文主要是介紹Oracle ID 自增代碼, Oracle ID 自增是計算機的實際應用中經常使用的計算機語言,如果你對其相關的代碼感興趣的話,你就可以點擊以下的文章對其進行了解,望你會有所收獲。
1.創建表
Sql代碼
- -- Create table
- create table USERS
- (
- ID NUMBER not null,
- USERNAME VARCHAR2(25),
- PASSWORD VARCHAR2(25),
- EMAIL VARCHAR2(50)
- )
- tablespace USERS
- pctfree 10
- initrans 1
- maxtrans 255
- storage
- (
- initial 64K
- minextents 1
- maxextents unlimited
- );
- -- Create/Recreate primary, unique and foreign key
constraints- alter table USERS
- add constraint ID primary key (ID)
- using index
- tablespace USERS
- pctfree 10
- initrans 2
- maxtrans 255
- storage
- (
- initial 64K
- minextents 1
- maxextents unlimited
- );
- -- Create table
- create table USERS
- (
- ID NUMBER not null,
- USERNAME VARCHAR2(25),
- PASSWORD VARCHAR2(25),
- EMAIL VARCHAR2(50)
- )
- tablespace USERS
- pctfree 10
- initrans 1
- maxtrans 255
- storage
- (
- initial 64K
- minextents 1
- maxextents unlimited
- );
- -- Create/Recreate primary, unique and foreign key constraints
- alter table USERS
- add constraint ID primary key (ID)
- using index
- tablespace USERS
- pctfree 10
- initrans 2
- maxtrans 255
- storage
- (
- initial 64K
- minextents 1
- maxextents unlimited
- );
2.創建序列
Sql代碼
- CREATE SEQUENCE SEQ_USERS_ID
- INCREMENT BY 1 -- 每次加幾個
- START WITH 1 -- 從1開始計數
- NOMAXVALUE -- 不設置最大值
- NOCYCLE -- 一直累加,不循環
- CACHE 10;
- CREATE SEQUENCE SEQ_USERS_ID
- INCREMENT BY 1 -- 每次加幾個
- START WITH 1 -- 從1開始計數
- NOMAXVALUE -- 不設置最大值
- NOCYCLE -- 一直累加,不循環
- CACHE 10;
3.創建觸發器
Sql代碼
- create or replace trigger TRI_USERS_ID
- before insert on users
- for each row
- declare
- -- local variables here
- begin
- SELECT SEQ_USERS_ID.NEXTVAL
- INTO :NEW.ID
- FROM DUAL;
- end TRI_USERS_ID;
- create or replace trigger TRI_USERS_ID
- before insert on users
- for each row
- declare
- -- local variables here
- begin
- SELECT SEQ_USERS_ID.NEXTVAL
- INTO :NEW.ID
- FROM DUAL;
- end TRI_USERS_ID;
- Oracle 11g Multimedia DICOM
以上就是對Oracle ID 自增的實際應用的代碼 的介紹,望你會有所收獲。
【編輯推薦】
責任編輯:佚名
來源:
互聯網