批量修改Oracle序列值的儲存過程
阿新 • • 發佈:2019-01-06
createorreplaceprocedure P_MODIFY_SEQUENCES is
--更新各序列值
str_sql varchar2(4000);
r boolean;
function F_MODIFY_SEQUENCE(sequenceName varchar2,taleName varchar2,keyF varchar2)return boolean
is
LastValue integer;
f_sql varchar2(4000);
Next_num number;
Max_num number;
begin
f_sql:='select max('||keyF||') from '|| taleName;
execute immediate f_sql into Max_num;
if(Max_num isnotnull) then
Next_num:=Max_num+1;
f_sql:='alter sequence '||sequenceName||' increment by 1 nocache';
execute immediate f_sql;
--f_sql:='select '||sequenceName||'.nextval from dual';
--execute immediate f_sql;
f_sql:='alter sequence '||sequenceName||' increment by 1 nocache';
execute immediate f_sql;
loop
f_sql:='select '||sequenceName||'.nextval from dual';
execute immediate f_sql into LastValue;
--select SE_DATATYPE.nextval into LastValue from dual;
exitwhen LastValue >= Next_num -1;
f_sql:= 'select '||sequenceName||'.nextval from dual';
execute immediate f_sql into LastValue;
--select SE_DATATYPE.nextval into LastValue from dual;
end loop;
f_sql:='alter sequence '||sequenceName||' increment by 1 cache 20';
execute immediate f_sql;
endif;
commit;
return true;
Exception
when others then
return false;
end F_MODIFY_SEQUENCE;
begin
r:=F_MODIFY_SEQUENCE('SE_DATATYPE','T_DATATYPE','DDID');
r:=F_MODIFY_SEQUENCE('SE_DATAITEM','T_DATAITEM','ITEMID');
end P_MODIFY_SEQUENCES;
/
--更新各序列值
str_sql varchar2(4000);
r boolean;
function F_MODIFY_SEQUENCE(sequenceName varchar2,taleName varchar2,keyF varchar2)return boolean
is
LastValue integer;
f_sql varchar2(4000);
Next_num number;
Max_num number;
begin
f_sql:='select max('||keyF||') from '||
execute immediate f_sql into Max_num;
if(Max_num isnotnull) then
Next_num:=Max_num+1;
f_sql:='alter sequence '||sequenceName||' increment by 1 nocache';
execute immediate f_sql;
--f_sql:='select '||sequenceName||'.nextval from dual';
--execute immediate f_sql;
f_sql:='alter sequence
execute immediate f_sql;
loop
f_sql:='select '||sequenceName||'.nextval from dual';
execute immediate f_sql into LastValue;
--select SE_DATATYPE.nextval into LastValue from dual;
exitwhen LastValue >= Next_num -1;
f_sql:=
execute immediate f_sql into LastValue;
--select SE_DATATYPE.nextval into LastValue from dual;
end loop;
f_sql:='alter sequence '||sequenceName||' increment by 1 cache 20';
execute immediate f_sql;
endif;
commit;
return true;
Exception
when others then
return false;
end F_MODIFY_SEQUENCE;
begin
r:=F_MODIFY_SEQUENCE('SE_DATATYPE','T_DATATYPE','DDID');
r:=F_MODIFY_SEQUENCE('SE_DATAITEM','T_DATAITEM','ITEMID');
end P_MODIFY_SEQUENCES;
/