我正在使用新创建的merge语句在db2中执行UPSERTS。
我认为结构正确,但问题是我得到了错误
'dddd'
我不确定问题出在哪里,因为它不是很明确,但似乎是我的价值观之一?
合并:
sqlstate[42000] syntax or access violation: Attributes not valid
答案 0 :(得分:1)
《 DB2 for iSeries手册》 https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/db2/rbafzmerge.htm包含以下示例。
MERGE INTO employee AS t
USING (VALUES(CAST(? AS CHAR(6)), CAST(? AS VARCHAR(12)),
CAST(? AS CHAR(1)), CAST(? AS VARCHAR(15)),
CAST(? AS SMALLINT), CAST(? AS INTEGER)))
s (empno, firstnme, midinit, lastname, edlevel, salary)
ON t.empno = s.empno
WHEN MATCHED THEN
UPDATE SET salary = s.salary
WHEN NOT MATCHED THEN
INSERT (empno, firstnme, midinit, lastname, edlevel, salary)
VALUES (s.empno, s.firstnme, s.midinit, s.lastname, s.edlevel,
s.salary)
也许您需要在SET
和最后的VALUES
语句中限定属性名称。
例如说is_active = is_active
而不是is_active = O.is_active
可能会使DB2感到困惑