将Oracle转换为DB2存储过程

时间:2018-06-26 03:20:03

标签: oracle stored-procedures db2

我是存储过程开发的新手,我需要将现有的Oracle存储过程转换为DB2语法。异常部分出现错误,请帮助

PS。从异常行开始

Oracle过程

:CREATE OR REPLACE PROCEDURE a.pUpsertDivision
(   error_code  OUT VARCHAR2,
    error_msg   OUT VARCHAR2,
    divId        IN INTEGER,
    divName      IN VARCHAR2,
    divDesc      IN VARCHAR2,
    retiredFlag  IN INTEGER
)
AS
BEGIN
    MERGE INTO a.DIVISION DIV
    USING DUAL
    ON
    (DIV.DIVISION_ID = divId)
    WHEN MATCHED THEN UPDATE
        SET DIV.DIV_NAME = divName,
        DIV.DIV_DESCRIPTION = divDesc,
        DIV.RETIRED_FLAG = retiredFlag
    WHEN NOT MATCHED THEN
        INSERT (DIVISION_ID,DIV_NAME,DIV_DESCRIPTION,RETIRED_FLAG)
        VALUES ((SELECT MAX(DIVISION_ID)+1 FROM a.DIVISION),divName,divDesc,retiredFlag);
    Commit;
    error_code := '1';
    EXCEPTION WHEN DUP_VAL_ON_INDEX THEN
        error_code := 'ERROR_CHUPSERT';
    WHEN OTHERS THEN
        error_code := SQLCODE;
        error_msg  := SUBSTR(SQLERRM,1,1000);
        RAISE_APPLICATION_ERROR(-20001, error_msg || ' Found error at pUpsertDivision');
END pUpsertDivision;
/

我尝试转换为db2,但是异常部分出现了问题

CREATE OR REPLACE PROCEDURE a.pUpsertDivision
(   
OUT error_code VARCHAR(4000),
OUT  error_msg  VARCHAR(4000),
 IN divId INTEGER,
 IN  divName VARCHAR(4000),
 IN  divDesc  VARCHAR(4000),
 IN retiredFlag INTEGER)
)
IS
BEGIN
    MERGE INTO a.DIVISION DIV
    USING DUAL
    ON
    (DIV.DIVISION_ID = divId)
    WHEN MATCHED THEN UPDATE
        SET DIV.DIV_NAME = divName,
        DIV.DIV_DESCRIPTION = divDesc,
        DIV.RETIRED_FLAG = retiredFlag
    WHEN NOT MATCHED THEN
        INSERT (DIVISION_ID,DIV_NAME,DIV_DESCRIPTION,RETIRED_FLAG)
        VALUES ((SELECT MAX(DIVISION_ID)+1 FROM a.DIVISION),divName,divDesc,retiredFlag);--
    Commit;--
    **EXCEPTION WHEN DUP_VAL_ON_INDEX THEN
        set error_code ='ERROR_CHUPSERT';--
WHEN OTHERS THEN
       set error_code= SQLCODE;--
       set error_msg  = SUBSTR(SYSPROC.SQLERRM,1,1000);--
        RAISE_APPLICATION_ERROR(-20001, error_msg || ' Found error at pUpsertDivision');--**
END;
/

1 个答案:

答案 0 :(得分:0)

IBM Database Conversion Workbench将帮助您将Oracle数据库转换为Db2,包括PL / SQL代码。 https://www.ibm.com/developerworks/community/groups/service/html/communityview?communityUuid=05901c97-75b2-47a1-9c32-25f748855913