DB2 存储过程 (ALTER) RESTART 编号列

DB2 Stored Procedure to (ALTER) RESTART the column with number

我正在使用 SSIS 包来更新我的开发 table 生产数据,使用 "Execute SQL Task" 到 运行 这些查询:

alter table DEV.tablename alter column ID drop identity;
delete from DEV.tablename;
insert into DEV.tablename SELECT * FROM RESTORE.COVERAGE;
alter table DEV.tablename  alter column ID set generated always as identity;
alter table DEV.tablename  alter column ID restart with some_Integer_value;

我无法通过参数(在上述情况下为some_Integer_value)将数字传递给passing parameter in execute SQL task执行SQL任务(SSIS),所以我不得不使用存储过程来运行 最后一个 ALTER table 语句。

CREATE PROCEDURE set_auto_incrementSP (IN TABLENAM VARCHAR(50),IN TABLECOLUM VARCHAR(30),IN INC_NUM INT)
    RESULT SETS 1
    LANGUAGE SQL

P1: BEGIN


    DECLARE STATEMENT1 VARCHAR(50);
    DECLARE NAME VARCHAR(30);
    DECLARE TABLENAME VARCHAR(50);
    DECLARE TABLECOLUMN VARCHAR(30);
    DECLARE INC_NUMBER INTEGER DEFAULT 0;

    SET TABLENAME=TABLENAM;
    SET TABLECOLUMN=TABLECOLUM;
    SET INC_NUMBER=INC_NUM;
    -- Declare cursor



        SET STATEMENT1 = 'ALTER TABLE '||TABLENAME||' alter column '||TABLECOLUMN||' restart with'||INC_NUMBER||' ';

        PREPARE NAME FROM STATEMENT1;

        EXECUTE IMMEDIATE STATEMENT1;

存储过程已成功部署,但在执行存储过程时,我看到此错误:

Run: DEV.SET_AUTO_INCREMENTSP(VARCHAR(50), VARCHAR(30), INTEGER) {? = call DEV.SET_AUTO_INCREMENTSP(?,?,?)}
[SQL0104] Token was not valid. Valid tokens: SET DROP RESTART. Run of routine failed.
- Roll back completed successfully.

STATEMENT1 是 50 长,这可能不够,而且您没有在 with 和数字

之间放置任何 space