Oracle重置序列(不删除重建方式)

DECLARE
  CURSOR cur_sequence IS
    SELECT do.owner || '.' || do.object_name sequence_name
      FROM dba_objects do
     WHERE do.object_type = 'SEQUENCE'
       AND do.owner IN ('XX')
       AND rownum = 1;
  l_start_num NUMBER;
  l_sql       VARCHAR2(1000);
  l_count     NUMBER := 0;


BEGIN
  FOR rec_seq IN cur_sequence LOOP
    l_count := l_count + 1;
    EXECUTE IMMEDIATE 'select ' || rec_seq.sequence_name || '.nextval from dual'
      INTO l_start_num;
    l_start_num := - (l_start_num) + 10000;
    l_sql        := 'alter sequence ' || rec_seq.sequence_name || ' increment by ' ||
                   l_start_num;
    EXECUTE IMMEDIATE l_sql;
    EXECUTE IMMEDIATE 'select ' || rec_seq.sequence_name || '.nextval from dual'
      INTO l_start_num;
    l_sql := 'alter sequence ' || rec_seq.sequence_name || ' increment by 1';
    EXECUTE IMMEDIATE l_sql;
    dbms_output.put_line('SEQ_NAME:'||rec_seq.sequence_name);
  END LOOP; --FOR rec_seq IN cur_sequence LOOP
  dbms_output.put_line('l_count:' || l_count);
END;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值