我正在尝试将以下查询传递给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
有人可以帮我解决一下吗?
答案 0 :(得分:0)
考虑使用MERGE语句来实现upsert操作(如果不存在,则插入其他更新)。示例位于DB2示例目录和DB2知识中心中。