您的位置:首页 > 数据库 > Oracle

Oracle创建序列存储过程

2012-09-14 20:59 302 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: