oracle有“自动号码”数据类型 [英] Does oracle have "auto number" data type

查看:182
本文介绍了oracle有“自动号码”数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我惊讶地发现,oracle没有自动编号数据类型。

解决方案

此博文描述了此功能的选项。




 创建序列test_seq 
start with 1
increment by 1
nomaxvalue;


其后按


 插入测试值(test_seq.nextval,'voila!'); 



创建触发器test_trigger
在测试之前插入
每行
begin
select test_seq.nextval into:new.id from dual;
end;



I am amazed to see that oracle does not have "auto number" data type. Is there any way to use auto number data type as we have this data type in MS access?

解决方案

This blog post describes an option for this functionality.

Key elements are quoted below, but the post goes into more depth.

create sequence test_seq 
start with 1 
increment by 1 
nomaxvalue;

Followed by

insert into test values(test_seq.nextval, 'voila!');

OR

create trigger test_trigger
before insert on test
for each row
begin
select test_seq.nextval into :new.id from dual;
end;

这篇关于oracle有“自动号码”数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆