Oracle 存储过程 每天凌晨 更新sequence 从0 开始
实现 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.
相关推荐
Omega 2020-08-16
zjyzz 2020-08-16
minggehenhao 2020-07-28
zhaojp0 2020-06-27
zjuwangleicn 2020-06-25
wenjieyatou 2020-06-17
liaomingwu 2020-06-16
hungzz 2020-06-16
muzirigel 2020-06-14
gsmfan 2020-06-14
ncomoon 2020-06-14
xiaobaif 2020-06-13
Rain 2020-06-12
hanshangzhi 2020-06-12
talkingDB 2020-06-12
IBMRational 2020-06-09
snowguy 2020-06-01