Oracle自动增长字段

Oracle自动增长字段
一 建立表

  1. create table xok.mytable
  2. (
  3. id number(2) primary key,
  4. name char(14),
  5. sex char(2) check (sex='' or sex=''),
  6. mark varchar2(1000)
  7. )

二 建立sequence

  1. create sequence XOK_AUTOINC 
  2. minvalue 1 
  3. start with 1 
  4. increment by 1 
  5. nocache;

三 建立触发器

  1. create or replace trigger INSERT_FOR_AUTOINC
  2.    before insert on xok.mytable  
  3.    for each row 
  4. declare 
  5.   -- local variables here
  6. begin 
  7.    select XOK_AUTOINC.nextval into:new.d from dual;
  8. end insert_for_autoinc;

四 用insert语句测试

  1. insert into xok.mytable values('','xxx','','xok.la');

五 查看结果

  1. select * from xok.mytable;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值