Create a Sequence with START WITH from Query

后端 未结 2 996
失恋的感觉
失恋的感觉 2020-12-10 12:35

How can I create a Sequence where my START WITH value comes from a query?

I\'m trying this way: CREATE SEQUENCE \"Seq\" INCREMENT BY 1 START WITH (SELECT MAX(

2条回答
  •  离开以前
    2020-12-10 12:44

    Here I have my example which works just fine:

    declare
     ex number;
    begin
      select MAX(MAX_FK_ID)  + 1 into ex from TABLE;
      If ex > 0 then
        begin
                execute immediate 'DROP SEQUENCE SQ_NAME';
          exception when others then
            null;
        end;
        execute immediate 'CREATE SEQUENCE SQ_NAME INCREMENT BY 1 START WITH ' || ex || ' NOCYCLE CACHE 20 NOORDER';
      end if;
    end;
    

提交回复
热议问题