DB2 查询令牌 SMALLINT 无效

DB2 Query Token SMALLINT was not valid

论坛。

我正在使用 IBM System i 7.1 版。

我在源代码中遇到以下合并语句的问题,因此我将其复制到数据库客户端以利用 "Run SQL Scripts" 功能。

我不想替换语句中@Variables 中的编码,而是想声明局部变量,以便我可以按原样测试语句。

添加了以下 'declare and set' 行,我收到以下错误:

declare @groupId smallint
set @groupId = 99

declare @groupName varchar(40)
set @groupName = 'Sam'

declare @groupId smallint

SQL State: 42601
Vendor Code: -104
Message: [SQL0104] Token SMALLINT was not valid. Valid tokens: DYNAMIC SENSITIVE ASENSITIVE INSENSITIVE. Cause . . . . . : A syntax error was detected at token SMALLINT. Token SMALLINT is not a valid token. A partial list of valid tokens is DYNAMIC SENSITIVE ASENSITIVE INSENSITIVE. This list assumes that the statement is correct up to the token. The error may be earlier in the statement, but the syntax of the statement appears to be valid up to this point. Recovery . . . : Do one or more of the following and try the request again: -- Verify the SQL statement in the area of the token SMALLINT. Correct the statement. The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to the order of clauses. -- If the error token is , correct the SQL statement because it does not end with a valid clause.

Processing ended because the highlighted statement did not complete >successfully

我试过在每行和开始和结束语句的末尾添加分号,但仍然没有成功。

下面是我要执行的完整语句:

declare @groupId smallint
set @groupId = 99

declare @groupName varchar(40)
set @groupName = 'Sam'


merge into database.table as t 
                 using ( values( cast(@groupId as smallint) 
                 ,cast(@groupName as varchar(40)) 
                 )) 
                 as caz( group_id
    , group_name
    ) 
                 on t.group_id = caz.group_id 
                 when matched then update
                 set t.group_name = caz.group_name 
                 when not matched then 
                 insert (   group_id
    , group_name
    ) 
                 values (caz.group_id
    , caz.group_name
    );

感谢任何帮助。

如果我可以提供更多信息,请告诉我。

我可能在这里找到了答案:

CREATE OR REPLACE VARIABLE variableName VARCHAR(50);
SET variableName = 'blah';
SELECT * FROM table WHERE column = variableName;
DROP VARIABLE variableName;

我还没有验证它是否成功。不过我相信这可能是本地问题。