oracle sequence语句重置方介绍
程序员文章站
2023-12-03 17:25: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;
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;
上一篇: 在ADF中跟踪SQL执行时间实现代码