dashDB:一个意外的令牌&#34; IF&#34;被发现&#34; &#34 ;.预期的代币可能包括:&#34; <call>&#34;。 SQLSTATE = 42601

时间:2017-07-13 07:19:17

标签: database db2 dashdb

我正在尝试将以下查询传递给dashdb:

IF (NOT EXISTS (SELECT * FROM TEST_CONFIGURATION WHERE DEVICEID = 'OZ_POLLUDRON_010')) 
BEGIN 
INSERT INTO TEST_CONFIGURATION (DEVICEID, DEVICETYPE, SERIAL, TYPE, MACID, CONFIG, INIT) VALUES('OZ_POLLUDRON_010', 'POLLUDRON_PRO', '9428424248', 0, '200050000b51343334363138', '[object Object]', '[object Object]')
END 

ELSE 
BEGIN 
UPDATE TEST_CONFIGURATION SET DEVICEID = 'OZ_POLLUDRON_010', DEVICETYPE = 'POLLUDRON_PRO', SERIAL = '9428424248', TYPE = 0, MACID = '200050000b51343334363138', CONFIG = '[object Object]', INIT = '[object Object]' WHERE DEVICEID = 'OZ_POLLUDRON_010' END

但它给了我以下错误:

database/sql/driver: [IBM][CLI Driver][DB2/LINUXX8664] SQL0104N An unexpected token "IF" was found following " ". Expected tokens may include: "<call>". SQLSTATE=42601

有人可以帮我解决一下吗?

1 个答案:

答案 0 :(得分:0)

考虑使用MERGE语句来实现upsert操作(如果不存在,则插入其他更新)。示例位于DB2示例目录和DB2知识中心中。