解决方法
DB2和sql标准在UPDATE语句中没有FROM子句.
所以你必须明确地将步骤分开
所以你必须明确地将步骤分开
>识别要修改的行和
>计算新值.
.
这是一个例子:
UPDATE TABLE A SET A.FLD_SUPV = ( SELECT B.FLD_SUPV FROM TABLEA A,TABLEB B,TABLEC C,TABLED D WHERE A.FLD1= B.FLD1 AND A.FLD_DT >= B.FLD_FM_DT AND A.FLD_DT <= B.FLD_THRU_DT AND A.FLD_DT > D.FLD_THRU_DT AND A.FLD_DT < C.FLD_EFF_DT ) WHERE EXISTS ( SELECT B.FLD_SUPV FROM TABLEA A,TABLED D WHERE A.FLD1= B.FLD1 AND A.FLD_DT >= B.FLD_FM_DT AND A.FLD_DT <= B.FLD_THRU_DT AND A.FLD_DT > D.FLD_THRU_DT AND A.FLD_DT < C.FLD_EFF_DT )
要更新两个字段,您可以使用如下示例:
UPDATE table1 t1 SET (col1,col2) = ( SELECT col3,col4 FROM table2 t2 WHERE t1.col8=t2.col9 )
优化器将看到SET和FROM子句中的子查询是相同的,它应该在内部执行计划中合并它们.