我正在使用IBM System i版本7.1。
我在源代碼中遇到了以下合併語句問題,所以我將它複製到數據庫客戶端以利用「運行SQL腳本」功能。
與其替換聲明中的@Variables中的編碼,我想聲明局部變量,以便我可以按原樣測試聲明。
中增加了以下「聲明並設置」行,我得到以下錯誤:
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
);
任何幫助表示讚賞。
請讓我知道,如果我可以提供任何信息。
閱讀[手冊中的複合語句]的正確語法可能是一個好主意(http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/db2/rbafzcompoundstmt.htm?lang= EN)。 – mustaccio
不僅語法。關於DECLARE VARIABLE的[docs也這樣說](http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/db2/rbafzdeclvar.htm?lang=en):「**調用**此語句只能嵌入到應用程序中「。 – user2338816