sqlserver2000 自增列identity是连续的,在orale里保证连续有点麻烦.可以尝试这样做: 取值的时候使用select max(自增列) from yourTable for update; 但可能有时候会引起效率问题.
----创建表 Create table t_user( Id number(6),userid varchar2(20),loginpassword varchar2(20),isdisable number(6) );----创建序列 create sequence user_seq increment by 1 start with 1 nomaxvalue nominvalue nocache----创建触发器 create or replace trigger tr_user before insert on t_popedom_user for each row begin select user_seq.nextval into :new.id from dual; end;----测试 insert into t_popedom_user(userid,loginpassword, isdisable) values('ffll','liudddyujj', 0); insert into t_popedom_user(userid,loginpassword, isdisable) values('dddd','zhang', 0) select * from t_user;
取值的时候使用select max(自增列) from yourTable for update; 但可能有时候会引起效率问题.
Create table t_user(
Id number(6),userid varchar2(20),loginpassword varchar2(20),isdisable number(6)
);----创建序列
create sequence user_seq
increment by 1
start with 1
nomaxvalue
nominvalue
nocache----创建触发器
create or replace trigger tr_user
before insert on t_popedom_user
for each row
begin
select user_seq.nextval into :new.id from dual;
end;----测试
insert into t_popedom_user(userid,loginpassword, isdisable)
values('ffll','liudddyujj', 0);
insert into t_popedom_user(userid,loginpassword, isdisable)
values('dddd','zhang', 0)
select * from t_user;
请问2楼,在使用序列的基础上,如果我要从其他表导入数据到Oracle那怎么做?
做个触发器,在insert时,将rownum提取出来进行自动插入。