您的位置:首页 > 数据库 > Oracle

Oracle里怎么建一个自增加的字段

2004-08-05 12:57 459 查看
用序列来实现
--建序列:
create sequence seq_name
increment by 1
start with 1
maxvalue 99999999999
nocycle
cache 10

--调用:
    insert into table(id,name) values(seq_name.nextval,'名字');

 

oracle中怎样将字段建成象SQL2000中的ID自动+1的字段
 两种方法
方法一:
  用触发器

建一个序列
   create sequence a_seq increment by 1 start with 100;
建一个触发器, 自动+1
create or replace trigger your_seq_tri
before insert on your_table1 for each row
declare
  next_id number;
begin
  select your_seq.nextval into next_id from dual;
  :new.id := next_id;
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐