oracle 储存过程 每天凌晨 更新sequence 从0 开始

CREATE OR REPLACE PROCEDURE seq_reset AS
  n    NUMBER(10);
  tsql VARCHAR2(100);
BEGIN
  EXECUTE IMMEDIATE 'select SQD_LSH.nextval from dual'
    INTO n;
  n    := - (n );
  tsql := 'alter sequence  SQD_LSH increment by ' || n;
  EXECUTE IMMEDIATE tsql;
  EXECUTE IMMEDIATE 'select  SQD_LSH.nextval from dual'
    INTO n;
    tsql := 'alter sequence SQD_LSH increment by 1';
  EXECUTE IMMEDIATE tsql;

END seq_reset;


先得到sequence的当前值,然后设置其步长为这个值的相反数,在执行nextval相当于减去已经增长的部分,使sequence重新归零,最后恢复步长为1.


然后 创建一个 job 设置成每天运行这个 存储过程即可

展开阅读全文

没有更多推荐了,返回首页