本文主要是介绍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
);
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
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
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
以上就是对Oracle ID 自增的实际应用的代码 的介绍,望你会有所收获。
【编辑推荐】