欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

oracle sequence语句重置方介绍

程序员文章站 2023-11-05 16:26:22
在开发过程中,可能会用到oracle sequence语句,本文以oracle sequence语句如何重置进行介绍,需要的朋友可以参考下oracle重置sequence语...
在开发过程中,可能会用到oracle sequence语句,本文以oracle sequence语句如何重置进行介绍,需要的朋友可以参考下
oracle重置sequence语句1
sql代码
复制代码 代码如下:

declare
n number(10 );
tsql varchar2(100 );
p_seqname varchar2(20 );
begin
p_seqname := 'seq_run_id';
execute immediate 'select ' || p_seqname || '.nextval from dual ' into n;
n := - (n - 1);
tsql := 'alter sequence '|| p_seqname ||' increment by ' || n;
execute immediate tsql;
execute immediate 'select ' || p_seqname || '.nextval from dual ' into n;
tsql := 'alter sequence '|| p_seqname ||' increment by 1' ;
execute immediate tsql;
exception
when others then
dbms_output.put_line( sqlerrm);
end;

oracle重置sequence语句2
sql代码
复制代码 代码如下:

create or replace procedure reset_sequence(p_sseqname in varchar2)
is
n number(10 );
tsql varchar2(100 );
begin
execute immediate 'select ' || p_sseqname || '.nextval from dual '
into n;
n := - (n - 1);
tsql := 'alter sequence ' || p_sseqname || ' increment by ' || n;
execute immediate tsql;
execute immediate 'select ' || p_sseqname || '.nextval from dual '
into n;
tsql := 'alter sequence ' || p_sseqname || ' increment by 1' ;
execute immediate tsql;
exception when others then
null;
end reset_sequence;