oracle MERGE INTO...USING兩表關聯操作(效率高),mergeinto...using

來源:互聯網
上載者:User

oracle MERGE INTO...USING兩表關聯操作(效率高),mergeinto...using

 資料量小的時候可以使用子查詢做兩表關聯操作;但資料量大的時候子查詢效率太低(因為是單條比對)

比如:

update person1 p1 set p1.p_name=(select p_name from person2 where p1.p_id=p2.p_id)  where p1.add_date>to_date('2014-09-01','yyyy-mm-dd')

而使用MERGE INTO...USING 作兩表關聯操作(增、刪、改)就效率非常高

MERGE INTO person1 p1         USING (select p_id,p_name from person2 where use='952701' ) p2        ON ( p1.p_id=p2.p_id )            WHEN MATCHED THEN UPDATE SET p1.p_name = p2.p_name where p1.add_date>to_date('2014-09-01','yyyy-mm-dd')    commit;




[oracle]兩表關聯的update操作問題

(a.z = b.z)的個數不唯一,那你要取哪個?
給你個取最大的:
update a set a.x =
(select max(b.x) from b where a.z = b.z )
where y=3
;
兩表資料多,只能通過在兩表z欄位建索引來加快速度。
 
ORACLE對於merge into用法

在when matched then 和 when not matched then 後面只能加insert() values 或者 update set ....,.... ,不能附加條件,而且then 後面的語句不能使用其他語句。 另外注意到,B的域只在using裡面的查詢有用吧 ,如果你要使用 也得是 在Using () M 用m吧
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.