2表(多表)update 2个(多个)值 sql怎么写?其中table1表100多万条数据,table2表30多万条,最多也就是更新table1中的30多万条,其余的不更新
更新1列,可以按下面的写,如果要更新多个值,sql怎么写?update table1 a
set a.col3 = nvl((select b.col3
from table2 b
where b.col1 = a.col1
and b.col2 = a.col2), a.col3);update操作怎么优化,能提高执行效率?
谢谢!
更新1列,可以按下面的写,如果要更新多个值,sql怎么写?update table1 a
set a.col3 = nvl((select b.col3
from table2 b
where b.col1 = a.col1
and b.col2 = a.col2), a.col3);update操作怎么优化,能提高执行效率?
谢谢!
这样会快点
update table1 a
set a.col3 = (select b.col3
from table2 b
where b.col1 = a.col1)
where exists (
select 1
from table2 b
where b.col1 = a.col1)
cursor c_name is select col1, col3 from table2;
begin
for tab in c_name loop
update table1
set col3=tab.col3
where col1.tab.col1;
end loop;
end;
被更新的表table1有几个index,不知道是不是跟index有关呢?
set a.col3 = (select b.col3
from table2 b
where b.col1 = a.col1
and b.col2 = a.col2 and b.col3 is not null );table2的col1,col2,col3加index
table1的index先drop掉,之后重建
update table1 a
set (a.col3,a.col4)=(select b.col3,b.col4
from table2 b
where b.col1=a.col1
and b.col2=a.col2)
像上面的语句,col1,col2都要建索引.