Oracle上没有自增字段,可以使用索引和触发器来达到此目的
第一步创建表
create table A(
userid number not null primary key,
username varchar not null
);
第2步:创建SEQUENCE
create sequence 序列化 increment by 1 start with 1 maxvalue 999999999;
第3步:创建一个基于该表的before insert 触发器,在触发器中使用该SEQUENCE
create or replace trigger bef_ins_t_country_define
before insert on 表名
referencing old as old new as new for each row
begin
new.country_id=s_country_id.nextval;
end;
第一步创建表
create table A(
userid number not null primary key,
username varchar not null
);
第2步:创建SEQUENCE
create sequence 序列化 increment by 1 start with 1 maxvalue 999999999;
第3步:创建一个基于该表的before insert 触发器,在触发器中使用该SEQUENCE
create or replace trigger bef_ins_t_country_define
before insert on 表名
referencing old as old new as new for each row
begin
new.country_id=s_country_id.nextval;
end;