
oracle表中创建序列语法:
CREATE SEQUENCE name
[INCREMENT BY n]
[START WITH n]
[{MAXVALUE n | NOMAXVALUE}]
[{MINVALUE n | NOMINVALUE}]
[{CYCLE | NOCYCLE}]
[{CACHE n | NOCACHE}]
示例:
increment by n:表明值每次增长n(步长)。
start with n: 从n开始。
{MAXVALUE n | NOMAXVALUE}: 设置最大值。
{MINVALUE n | NOMINVALUE}: 设置最小值,start with不能小于最小值。
CYCLE | NOCYCLE : 是否循环,建议不使用
CACHE n | NOCACHE : 是否启用缓存。
2、插入数据到表中
示例:
INSERT INTO emp VALUES
(emp_sequence .nextval, 'LEWIS', 'CLERK',7902, SYSDATE, 1200, NULL, 20)
Oracle数据库系统是目前世界上流行的关系数据库管理系统,系统可移植性好、使用方便、功能强,适用于各类大、中、小、微机环境。它是一种高效率、可靠性好的 适应高吞吐量的数据库解决方案。
ORACLE数据库是目前世界上使用最为广泛的数据库管理系统,作为一个通用的数据库系统,它具有完整的数据管理功能;作为一个关系数据库,它是一个完备关系的产品;作为分布式数据库它实现了分布式处理功能。
扩展资料:
sql server数据库里建序列:
alter table cust_info add sequence int
insert into cust_info (sequence)
select row_number() over(order by cust_id) as cust_id_seq from cust_info
oracle可以直接生成数字序列:select rownum from dual connect by rownum<=100
如果是对表中的数据排序后生成行号,可以用窗口函数:
select row_number() over ([partition by part_fieldname] order by sort_fieldname[desc]) ,fieldname1,fieldname2 from t
oracle的自增需要依靠序列和触发器共同实现
比如
先创建一个表
create table test(id int primary key,name varchar2(10))
创建一个序列
create sequence test_seqincrement by 1
start with 1
minvalue 1
maxvalue 9999999999999
nocache
order
触发器实现
create or replace trigger test_triggerbefore insert on testfor each row
begin
select test_seq.Nextval into:new.id from dual
end
然后你试试吧
insert into test (name) values ('张三')欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)