以下查询失败。如何纠正我需要将TBL_PLANNING_REPOSITORY
中的最大ID放在创建序列中以。
CREATE sequence auto_id_planning_repo
start with (select MAX(ID) from TBL_PLANNING_REPOSITORY) increment by 1;
答案 0 :(得分:2)
使用动态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;
答案 1 :(得分:0)
DDL语句不能与DML表达式混合使用。正确的方法是这样的:
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';