Home > Database > Mysql Tutorial > Oracle 动态主键序列创建

Oracle 动态主键序列创建

WBOY
Release: 2016-06-07 14:57:54
Original
1601 people have browsed it

1.要保留原始的数据时,避免主键重复。每次删除序列再重建是不是很较麻烦呢?那么用这个语句简单方便多了。 3个参数:order_sq是序列名。order是表名,内部的主键是id。 2.写完语句验证是否正确可以用pl/slq-新建-测试窗口,进行单步调试。谢谢。 Oracle drop

1.要保留原始的数据时,避免主键重复。每次删除序列再重建是不是很较麻烦呢?那么用这个语句简单方便多了。
3个参数:order_sq是序列名。order是表名,内部的主键是id。

2.写完语句验证是否正确可以用pl/slq->新建->测试窗口,进行单步调试。谢谢。
Oracle
drop sequence order;
declare
v_sql varchar2(1000);
v_num number(20):=1;
begin
v_sql:='create sequence order_sq';
select max(order_sq.id)+1 into v_num from order;
if v_num is null then v_num :=1;
end if;
v_sql:=v_sql||' minvalue 1 maxvalue 9999999999999999999999999999 start with '||v_num ||' increment by 1 cache 20';
execute immediate v_sql;
end;
Copy after login
Oracle 动态主键序列创建
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template