带有WITH子句的SQL太多值错误

时间:2016-06-21 01:04:14

标签: sql oracle11g sqlplus with-statement

- 此查询返回了太多的值"错误。我不确定为什么?

   update myTable
            set var1= var2
            WHERE value1 IN (

             WITH X AS
            (
            select value1, value2, var1,var2, ROW_NUMBER()
            OVER
            (PARTITION BY value1 ORDER BY value1 desc) as rn
            from
              mytable WHERE var1 is null AND rownum>0 and rownum<=10 order by value1 asc
            )
            SELECT
            value1, value2, var2,var1
           FROM X WHERE rn=1  and var1 is null and rownum>0 and rownum<=10);

2 个答案:

答案 0 :(得分:1)

错误too many values是因为查询具有value1 IN (),其中在内部查询中选择了多个列。为避免这种情况,只需在内部查询中select value1。

update myTable
set var1 = var2
WHERE value1 IN
     (select value1 from 
       (select value1, value2, var1,var2, 
        ROW_NUMBER() OVER (PARTITION BY value1 ORDER BY value1 desc) as rn
        from mytable 
        WHERE var1 is null
        ) t 
      where rn <= 10
      )

答案 1 :(得分:0)

我认为使用character set更好地提供了您的意图:

exists