Oracle新建表字段,如何使字段自增
发布日期:2021-06-24 06:54:32 浏览次数:4 分类:技术文章

本文共 446 字,大约阅读时间需要 1 分钟。

oracle的自增需要依靠序列和触发器共同实现

比如 新建一张表 

create table test

(id 
int 
primary 
key
,
name 
varchar2(10));
 
创建一个序列
create 
sequence 
test_seq increment 
by 
1 start 
with 
minvalue 1 maxvalue 9999999999999 nocache 
order
;
 
触发器实现
create 
or 
replace 
trigger 
test_trigger
before 
insert 
on 
test
for 
each 
row
begin
  
select  
test_seq.Nextval 
into
:new.id 
from 
dual;
end
;
 
然后插入数据
insert 
into 
test (
name
values 
(
'张三'
);

转载于:https://www.cnblogs.com/yachao1120/p/8669309.html

转载地址:https://blog.csdn.net/weixin_30896763/article/details/98276099 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:c#中 xml和json 互相转换
下一篇:Oledb 读取execl

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月05日 01时29分59秒