是DB2的新手。我正在尝试将此sp从Microsoft SQL Server转换为DB2 这是来自Microsoft SQL的代码:
DECLARE @DELIMITER VARCHAR(1) =','
DECLARE @FILTER_TYPE VARCHAR(128) ='Animal_ID_17'
DROP TABLE IF EXISTS #tmp_Inputs
CREATE TABLE #tmp_Inputs
(
INPUT_VALUE VARCHAR(128)
)
INSERT INTO #tmp_Inputs(INPUT_VALUE)
SELECT COL1 FROM [dbo].[fn_Split_String](@INPUT_VALUE,@DELIMITER)
DROP TABLE IF EXISTS #tmp_Animals
CREATE TABLE #tmp_Animals
(
ANIMAL_ID VARCHAR(128)
)
IF @FILTER_TYPE ='Animal_Id_17'
BEGIN
INSERT INTO #tmp_Animals
(
ANIMAL_ID
)
SELECT a.ANIMAL_ID
FROM #tmp_Inputs t
INNER JOIN ANIMALS a ON t.INPUT_VALUE = a.ANIMAL_ID
END
SELECT * FROM #tmp_Animals
ORDER BY ANIMAL_ID
这是我转换为DB2之后的sp
DECLARE @FILTER_TYPE VARCHAR(128);
SET @FILTER_TYPE = 'Animal_ID_17';
DECLARE @DELIMITER VARCHAR(3);
SET @DELIMITER = ',';
DECLARE GLOBAL TEMPORARY TABLE Input_EMP
(
INPUT_VALUE VARCHAR(128)
);
INSERT INTO Input_EMP(INPUT_VALUE)
SELECT COL1 FROM fn_Split_String @INPUT_VALUE,@DELIMITER;
DECLARE GLOBAL TEMPORARY TABLE Animals_EMP
(
ANIMAL_ID VARCHAR(128)
);
IF @FILTER_TYPE ='Animal_Id_17' THEN
INSERT INTO Animals_EMP
(
ANIMAL_ID
)
SELECT a.ANIMAL_ID
FROM Input_EMP a
JOIN ANIMALS n on a.INPUT_VALUE = n.ANIMAL_ID;
END IF;
DECLARE cursor1 CURSOR WITH RETURN for
SELECT ANIMAL_ID
FROM Animals_EMP
ORDER BY ANIMAL_ID;
OPEN cursor1;
然后我得到了这个错误: 在“”之后发现意外的令牌“”。预期的令牌可能包括:“” .. SQLCODE = -104,SQLSTATE = 42601,DRIVER = 4.19.56
有人知道如何解决此错误。谢谢
答案 0 :(得分:0)
Db2 compound SQL statements要求DECLARE
语句位于任何可执行语句之前,并遵循明确定义的顺序,如链接文档中所示。在您的代码中,它们分散在各处,这就是错误消息试图告诉您的内容。