How to create an Oracle sequence starting with max value from a table?

后端 未结 8 1340
[愿得一人]
[愿得一人] 2020-12-02 20:14

Trying to create a sequence in Oracle that starts with the max value from a specific table. Why does this not work?

CREATE SEQUENCE transaction_sequence
  MI         


        
8条回答
  •  我在风中等你
    2020-12-02 20:35

    use dynamic sql

    BEGIN
                DECLARE
                maxId NUMBER;
                  BEGIN
                  SELECT MAX(id)+1
                  INTO maxId
                  FROM table_name;          
                  execute immediate('CREATE SEQUENCE sequane_name MINVALUE '||maxId||' START WITH '||maxId||' INCREMENT BY 1 NOCACHE NOCYCLE');
                  END;
    END;
    

提交回复
热议问题