表如下:
create table _users
(
user_id number(8) not null , --pk
user_name varchar2(10)
)我要向表中添加数据时user_id 自增怎么做啊 从00000001开始自增 下一个就是00000002
create table _users
(
user_id number(8) not null , --pk
user_name varchar2(10)
)我要向表中添加数据时user_id 自增怎么做啊 从00000001开始自增 下一个就是00000002
start with 00000001
increment by 1insert into _users values(_users_seq.NEXTVAL,'sssss')
insert into _users values(_users_seq.NEXTVAL,'fff')
这样不行啊 还是以1自增 下一个是2 我要这样的00000001,00000002,00000003
你自己用lpad把0拼上去不就可以了
LPAD(CTXSYS.DR_ID_SEQ.NEXTVAL,
------------------------------
00001417
SQL>
为啥?
rownun<=你想要的数~~~
已写入 file afiedt.buf 1 create sequence seq_user_id
2 start with 1
3 increment by 1
4* cache 20
SQL> /序列已创建。SQL> edi
已写入 file afiedt.buf 1 create table users
2 (
3 user_id varchar(8) not null,
4 user_name varchar2(10)
5* )
6 /表已创建。SQL> edi
已写入 file afiedt.buf 1 create or replace trigger tri_user_id before insert on users for each row
2 declare
3 v_user_id users.user_id%type;
4 begin
5 select seq_user_id.nextval into v_user_id from dual;
6 :new.user_id:=lpad(v_user_id,8,0);
7* end;
SQL> /触发器已创建SQL> insert into users(user_name) values('wkc168')
2 /已创建 1 行。SQL> commit;提交完成。SQL> select user_id,user_name from users;USER_ID USER_NAME
-------- ----------
00000001 wkc168