To dinya2003(OK) :
想实现以tblcustomerTmp表中记录更新符合条件的tblcustomer 表中的concat_addr字段。
tblcustomer中总共有40000多条记录,tblcustomerTmp中有15000多条记录。
原来有个where条件:
WHERE exists(
  SELECT c.concat_addr 
  FROM tblcustomerTmp c
  WHERE a.vin=c.vin and a.qad_userid is not null 
  and a.category_flag='C' and a.status_flag=1
  and substr(a.qad_userid,length(rtrim(a.qad_userid))-5,6)
  =substr(a.vin,length(a.vin)-5,6)
)
加上where子句后执行超过1个多小时尚未执行完毕,郁闷!求高人解答!

解决方案 »

  1.   

    同意楼上的。你的update没有where条件,会更新tblcustomer表的所有记录。另外你的内层where句中的条件用到了substr和null判断,index用不上,也会影响速度的。
      

  2.   

    换个思路,不要用一条sql完成所有的事。不是很清楚你的需求,随便说两句。
    用pl/sql,先以某个条件从tblcustomerTmp选出若干条记录,这个条件要能够尽可能的把范围缩小,又可以用上index。然后在loop中,用你的业务逻辑check该条纪录,ok的话,如果该条记录在tblcustomer中存在的话,执行update(你的这两个表的主键应该是一样的吧)2个几万条记录的表,只要数据库的配置不是很离谱,几分钟内应给可以执行完毕的。
      

  3.   

    我终于搞定了,再OTN上的老外回的一篇帖子中找到了,执行只需几秒钟就完毕了,爽!不敢藏私,贡献给大家,不过一定要注意连接中最好使用主键连接。
    update (
      SELECT a.concat_addr addr1, b.concat_addr addr2, a.title title1, b.title title2, 
            a.sex_code sex_code1, b.sex_code sex_code2, a.cust_mp cust_mp1, b.cust_mp cust_mp2, 
            a.province province1, b.province province2, a.city city1, b.city city2, 
            a.cust_postcode cust_postcode1, b.cust_postcode cust_postcode2
      FROM tblcustomer a,tblcustomerTmp b
      WHERE 
       a.cust_id=b.cust_id 
      and a.category_flag='C' and a.status_flag=1
      and substr(a.qad_userid,length(trim(a.qad_userid))-5,6)
      =substr(a.vin,length(a.vin)-5,6)
    )
    set addr1=addr2, title1=title2, sex_code1=sex_code2, cust_mp1= cust_mp2, province1=province2, 
        city1=city2, cust_postcode1=cust_postcode2