Oracle中varchar2类型的id为自动增长

Oracle中id的类型为varchar2(10)主键,怎样创建自动增长的id

可以的,使用序列

创建序列

create sequence SEQ_CEID
minvalue 1
maxvalue 9999999999
start with 41
increment by 1
cache 20;
创建表,插入,查询
create table table_f (
id varchar(10) primary key,
name varchar(20)
)
insert into table_f values(SEQ_CEID.NEXTVAL,'wef')

或者加上触发器

2.--创建表

3.create table book(

  1. bookId varchar2(4) primary key,
  2. name varchar2(20)
    6.);
    7.--创建序列
    8.create sequence book_seq start with 1 increment by 1;
  3. 10.--创建触发器
    11.create or replace trigger book_trigger
    12.before insert on book
    13.for each row
    14.begin
    15.select book_seq.nextval into :new.bookId from dual;
    16.end ;
    17.--添加数据
    18.insert into book(name) values ('cc');
    19.insert into book(name) values ('dd');