create or replace procedure createSequence(tableName in varchar2) is
indexStart number ;
cou number ;
tName varchar2(200);
str varchar2(8000);
begin
tName:= tableName;
str:= 'select count(*) as int from tab where tname=upper('''|| tName||''')' ;
dbms_output.put_line(str);
execute immediate str into cou ;
if cou>0 then
begin
str:= 'select nvl(max(id),0)+1 from ' || tableName ;
execute immediate str into indexStart ;
str:='create sequence SEQUENCE_' || tName || ' minvalue 1 maxvalue 999999999999999999999999999 start with '|| indexStart ||' increment by 1 nocache';
dbms_output.put_line(str);
execute immediate str;
end;
end if ;
end createSequence;
测试语句:
SELECT SEQUENCE_TABLENAME.NEXTVAL FROM DUAL;