Requirements:
Update the same records in Table T1 (t_statbuf) and Table T1 (t_mt) to table T1.
1. incorrect syntax:
update table_name t1 set (a,b,c)=( select a,b,c from table_name_2 t2 where t1.a=t2.a);
In this way, all rows in Table T1 will be updated: If t1.a = t2.a, the records found in Table T2. if t1.a <> t2.a, records in T1 are updated to null ).
Correct syntax:
update table_name t1 set (a,b,c)=( select a,b,c from table_name_2 t2 where t1.a=t2.a) where exists(select 1 from table_name_2 t2 where t1.a=t2.a);
Resolution:
The correct statement is followed by a where exists (select 1 from table_name_2 T2 where t1.a = t2.a );
If t1.a = t2.a exists, it is updated. Otherwise, it is not updated, so it will not cause all records in Table T1 to be updated.
Example:
Update table_name_1 set (a, B) = (select 1, 2 from dual where 1 = 2 );
In this result, all records in table_name_1 are updated to null because 1 = 2 is not valid.
Summary:
During update, you must confirm the conditions and test the conditions!
My test statement:
update my_time_test1 t1 set (MDATE,DISCRIPT) =(select MDATE,DISCRIPT from my_time_test t2 where t1.DISCRIPT=t2.DISCRIPT) where exists (select 1 from my_time_test t2 where t1.DISCRIPT=t2.DISCRIPT);
My business statement:
Update t_mt T1 set (stat, ostat, rpttime) = (select stat, stat, rpttime from t_statbuf T2 where t1.msgid = t2.msgid) where exists (select 1 from t_statbuf T2 where t1.msgid = t2.msgid); -- If t1 and t2 are equal, update. If the where exists clause is not added, it is updated and does not exist no matter whether the storage does not exist. The result is updated to null, but the record is still