假如有两条SQL语句,要对同一张表进行update操作。数据库为Oracle10g。
语句1:update table_name set field1=x1, field2=x2 where id=1
语句2:update table_name set field1=y1, field2=y2 where id=2现在想把这两条语句合为一条,以减少对数据库的操作。请问有何办法?
语句1:update table_name set field1=x1, field2=x2 where id=1
语句2:update table_name set field1=y1, field2=y2 where id=2现在想把这两条语句合为一条,以减少对数据库的操作。请问有何办法?
update table_name a set (a.field1,a.field2)=(select x1,x2 from b where b.id=a.id)
and exists(select 1 from b where b.id=a.id)
2、使用存储过程,数据存入索引表、嵌套表(类似数组),然后批量更新。