update testaa 
set name1=(select mingcheng from testcc where rownum=1 and bianhao=testaa.id1) 
where exists(select 1 from testcc where bianhao=testaa.id1);(wildwave回答)为什么批量更新时rownum找出的是我想要的数据?
select mingcheng from testcc where bianhao=testaa.id1 出现几条数据 rownum怎么对应的?

解决方案 »

  1.   

    为什么批量更新时rownum找出的是我想要的数据? 
    这是什么意思..
    上面写的语句里,加上rownum=1就是当出现多条记录时取第一条。否则会出现错误
      

  2.   

    你的testcc表中是不是有bianhao重复的数据啊....rownum=1是同一个bianhao只取其中一条mingcheng记录。
      

  3.   

    恩,是的,因为查询select mingcheng from testcc where bianhao=testaa.id1 是多条数据rownum取第一条,但是怎么保证我需要的数据出现在rownum=1的位置.我不明白,所以再次提问那帖子的结果正确,所以我把那帖子结了.
      

  4.   


    rownum=1是取同一个bianhao下的一条mingcheng记录。在testcc中你同样的bianhao,应该也对应同样的mingcheng。。
      

  5.   

    那么就有一个问题,当返回多条数据的时候如何知道哪一条是你想要的。如果多条记录的值都是重复的就无所谓了
    你执行下列查询看看
    select a.*,b.mingcheng
    from testaa a,testcc b
    where a.id1=b.bianhao(+)
      

  6.   

    主要是根据bianhao=testaa.id1这个条件来关联的