如何根据相关表更新DB2中的值子集?

时间:2013-04-05 00:33:49

标签: sql db2 db2-luw

我正在尝试从DB2数据库中的CLOB字段中删除最后10个字符。我可以这样做:

UPDATE  report
SET     comment = LEFT(comment, (LENGTH(comment) - 10))

但是,我想根据报告是否在当前报告周期内将截断限制为行的子集。我试过这个......

UPDATE  report
SET     comment =
        (   SELECT  LEFT(comment, (LENGTH(comment) - 10))
            FROM    report

                    INNER JOIN report_period
                    ON report.report_period_id = report_period.report_period_id

            WHERE   report_period.name = '2013 Interim Report'  )

......但我得到了

The result of a scalar fullselect, SELECT INTO statement, or
VALUES INTO statement is more than one row

我做错了什么?

1 个答案:

答案 0 :(得分:0)

没关系......问这个问题有助于清除它。只需将连接移动到WHERE子句....

UPDATE  report
SET     comment = LEFT(comment, (LENGTH(comment) - 10))
WHERE   report_id IN
        (   SELECT  report_id 
            FROM    report

                    INNER JOIN report_period
                    ON report.report_period_id = report_period.report_period_id

            WHERE   report_period.name = '2013 Interim Report'  )