oracle学习笔记 一

Oracle自增长ID实现
本文介绍了两种在Oracle数据库中实现自增长ID的方法:第一种直接使用序列生成ID;第二种通过创建序列和触发器来自动填充ID字段。这两种方法都能有效地为表中的每一行分配唯一的自增长标识符。


oralce 开发:
1,自增长序列
方法一:建表,建序列
create table mytable
(
id number primary key,
name char(14),
sex char(2) check (sex='1' or sex='0'),
mark varchar2(1000)
)

create sequence XOK_AUTOINC 
minvalue 1 
start with 1 
increment by 1 
nocache;

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

方法二:
建表,见序列,建触发器

 

create table mytable
(
id number primary key,
name char(14),
sex char(2) check (sex='1' or sex='0'),
mark varchar2(1000)
)

create sequence XOK_AUTOINC 
minvalue 1 
start with 1 
increment by 1 
nocache;

create or replace trigger INSERT_FOR_AUTOINC
   before insert on mytable  
   for each row 
begin 
   select XOK_AUTOINC.nextval into :new.id from dual;
end insert_for_autoinc;


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

 

 

插入时间:to_date('2007-12-28 10:07:24' , 'yyyy-mm-dd hh24:mi:ss')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值