-- #############################################################################################
--
-- %Purpose: Script to increase a sequence above the value the related attribute has
--
-- #############################################################################################
--
-- Akadia SQL utils
--
-- Can be used after data migrations
--
-- Paramters:
--   1: sequence name
--   2: table name
--   3: attribute name
--
-- Sample usage:
--   @incseq.sql my_sequence my_table my_attribute
--
--------------------------------------------------------------------------------
--
SET SERVEROUTPUT ON SIZE 1000000;
--
DECLARE
  dummy NUMBER := 0;
  curr  NUMBER := 0;
BEGIN
        --
  SELECT &1..nextval INTO dummy FROM dual;
  dbms_output.put('start with next value=' || dummy);
        --
  SELECT max(&3) INTO curr FROM &2;
  WHILE dummy < curr LOOP
    SELECT &1..nextval INTO dummy FROM dual;
  END LOOP;
  --
  dbms_output.put_line(', end=' || dummy);
  --
END;
/
