UPDATE bcn_addr_maint c SET
(
addr_type,
build_code,
addr1,
addr2,
addr3,
addr4,
addr5,
addr_code,
floor,
flat_rm,
region
)
=
(
SELECT
addr_type,
build_code,
addr1,
addr2,
addr3,
addr4,
addr5,
addr_code,
floor,
flat_rm,
region
FROM bc_cus_addr b
WHERE a.pps=b.pps AND a.addr_type=b.addr_type and a.circuit_no is null and a.line_no is null
)
;以上table数据的update那样写吗??

解决方案 »

  1.   

    语法是:
    UPDATE a SET
      (c1,c2,c3
      ) =
      (SELECT b1,b2,b3 FROM b where......
      ) WHERE ......;好象少写了最外层的where 条件
      

  2.   

    可以这样写,但是这种方式必须是要子查询,也即是说这种方式不行
    update table set (c1,c2)=(value1,value2)...
      

  3.   

    结果是addr1,addr2,addr3,addr4都是null哦。但是有时候又可以。
    网上搜索得到的结果是要update那里要多一个clause:WHERE exists (select 1 from FROM bc_cus_addr b a.pps=b.pps AND a.addr_type=b.addr_type and a.circuit_no is null and a.line_no is null)我觉得应该是要多加一个clause。你们觉得呢?
      

  4.   

    select 里面的条件在update语句最后再用where exists 重新写一遍一摸一样的就好
      

  5.   

    楼主的写法是正确的。偷了个懒,只见了一个测试表。
    create table resource_tab(
     BeginResId number,
     EndResId number,
     count number,
     price number
    );insert into resource_tab values(10001,10005,5,100);
    insert into resource_tab values(10007,10012,6,200);  update resource_tab rt
         set (rt.beginresid, rt.endresid, rt.count) =
             (select rt1.beginresid + 1, rt1.endresid + 1,rt1.count
                from resource_tab rt1
               where rt1.beginresid = rt.beginresid
                 and rt1.endresid = rt.endresid)
      

  6.   

    批量更新一定要注意update 的表后面要跟个where条件加以限制,如果不限制就是update整张表,可以这样写
    UPDATE bcn_addr_maint a SET
    (
    addr_type,
    build_code,
    addr1,
    addr2,
    addr3,
    addr4,
    addr5,
    addr_code,
    floor,
    flat_rm,
    region
    )
    =
    (
    SELECT
    addr_type,
    build_code,
    addr1,
    addr2,
    addr3,
    addr4,
    addr5,
    addr_code,
    floor,
    flat_rm,
    region
    FROM bc_cus_addr b
    WHERE a.pps=b.pps AND a.addr_type=b.addr_type and a.circuit_no is null and a.line_no is null
    ) where exists(select 1 FROM bc_cus_addr c
    WHERE a.pps=c.pps AND a.addr_type=c.addr_type and a.circuit_no is null and a.line_no is null);