合并db2错误中的无效属性

时间:2018-11-16 18:28:18

标签: sql merge db2

我正在使用新创建的merge语句在db2中执行UPSERTS。

我认为结构正确,但问题是我得到了错误

'dddd'

我不确定问题出在哪里,因为它不是很明确,但似乎是我的价值观之一?

合并:

sqlstate[42000] syntax or access violation: Attributes not valid

1 个答案:

答案 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感到困惑