我正在使用 liquibase 来管理我的架构。我有一堆插入语句。我已经硬编码了主 ID 号码。完成所有插入后,我想将序列值更改为比表中主键的最大值大 1。为此,我编写了如下所示的 PL/SQL。但是,当我执行时,select ArtifactTypes_id_seq.nextval from dual;
它仍然递增 0。
SET SERVEROUTPUT ON SIZE 1000000
DECLARE
sequence_id NUMBER;
BEGIN
SELECT NVL(MAX(idArtifactType), 0) + 1 INTO sequence_id FROM ArtifactTypes;
EXECUTE IMMEDIATE 'ALTER SEQUENCE saas.ArtifactTypes_id_seq INCREMENT BY ' || sequence_id;
EXECUTE IMMEDIATE 'SELECT ArtifactTypes_id_seq.nextval FROM dual';
EXECUTE IMMEDIATE 'ALTER SEQUENCE saas.ArtifactTypes_id_seq INCREMENT BY 1';
DBMS_OUTPUT.put_line('Executed "ALTER SEQUENCE saas.ArtifactTypes_id_seq INCREMENT BY ' || sequence_id || '"');
END;
/
DBMS_OUTPUT 提供以下输出 -
Executed "ALTER SEQUENCE saas.ArtifactTypes_id_seq INCREMENT BY 71"
我错过了什么?我做错了吗?注意:我尝试从 SQLDeveloper 执行这些 SQL。