0

The Below query is failing. How to correct it I need to put max id from TBL_PLANNING_REPOSITORY in the create sequence start with.

CREATE sequence auto_id_planning_repo 
start with (select MAX(ID) from TBL_PLANNING_REPOSITORY) increment by 1;

2 Answers 2

2

Use dynamic sql.

DECLARE
   v_startwith   NUMBER;
BEGIN
   SELECT MAX (ID) INTO v_startwith FROM TBL_PLANNING_REPOSITORY;

   EXECUTE IMMEDIATE
      'create sequence auto_id_planning_repo  start with ' || v_startwith || ' increment by 1';
END;
Sign up to request clarification or add additional context in comments.

Comments

0

DDL statements cannot be mixed with DML expressions. Correct way is something like this:

lock table tbl_planning_repository in exclusive mode;
var m number;
exec select max(id) into :m from tbl_planning_repository;
exec execute immediate 'create sequence ... start with ' || :m || ' increment by 1'; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.