SELECT costmgmt.SEQ_ID.nextval FROM dual;
DECLARE
vnumber NUMBER;
nnumber NUMBER;
BEGIN
SELECT ( (SELECT max(pn.ID ) FROM COSTMGMT.PN pn) -
costmgmt.SEQ_ID.nextval )
INTO vnumber
FROM dual;
IF vnumber > 0 THEN
EXECUTE IMMEDIATE 'ALTER SEQUENCE costmgmt.SEQ_ID INCREMENT BY ' || vnumber;
SELECT costmgmt.SEQ_ID.nextval INTO nnumber FROM dual;
EXECUTE IMMEDIATE 'ALTER SEQUENCE costmgmt.SEQ_ID INCREMENT BY 1 cache 20';
END IF;
END;