dingjun123 发表于 2016-5-9 16:38
update a set a.bill=(select b.bill from b where a.acc=b.acc and a.billb.bill)
where exists(select...
多行返回的都可以这样做吗 更新的记录是一条条对应的吗
dingjun123 发表于 2016-5-9 16:38
update a set a.bill=(select b.bill from b where a.acc=b.acc and a.billb.bill)
where exists(select...
这样的效率貌似有点低,现在a、b表虽然有点大,但是符合条件的只有几十个,但是我更新了10来分钟还没结束
t069064449 发表于 2016-5-9 17:01
这样的效率貌似有点低,现在a、b表虽然有点大,但是符合条件的只有几十个,但是我更新了10来分钟还没结束
那就改成merge啊
merge into a using b on (a.acc=b.acc)
when matched
then
update set a.bill=b.bill
where a.billb.bill;
确实快很多
SQL> create table tablea as select level acc,'name'||level bill from dual connect by level create table tableb as select level acc,'name'||level bill from dual connect by level update tableb set bill='xxx' where mod(acc,1000)=0;
已更新1000行。
已用时间:00: 00: 01.54
SQL> commit;
提交完成。
已用时间:00: 00: 00.01
SQL> update tablea a set a.bill=(select b.bill from tableb b where a.acc=b.acc and a.billb.bill)
2 where exists(select 1 from tableb b where a.acc=b.acc and a.billb.bill);
已更新1000行。
已用时间:00: 01: 38.34
SQL> select count(*) from tablea where bill='xxx';
COUNT(*)
----------
1000
已用时间:00: 00: 00.09
SQL> rollback;
回退已完成。
已用时间:00: 00: 00.04
SQL> select count(*) from tablea where bill='xxx';
COUNT(*)
----------
0
已用时间:00: 00: 00.04
SQL> merge into tablea a using tableb b on (a.acc=b.acc)
2 when matched
3 then
4 update set a.bill=b.bill
5 where a.billb.bill;
1000 行已合并。
已用时间:00: 00: 00.99
SQL> select count(*) from tablea where bill='xxx';
COUNT(*)
----------
1000
已用时间:00: 00: 00.04