Home > database >  For a joint update Oracle update concise writing
For a joint update Oracle update concise writing

Time:03-23

SQL function, the a5 data in a table, according to add and subtract the sum by the sign of a4 will be b and b in the table fields of sum and update the table b

 update TB bThe set b.b=b.b + (select sum (decode (a.a 4, '0', a.a 5, '1', (0 to 5) a.a, 0)) from ta a 
Where a.a 1 and 1=b.b a.a 2=2 and 3=b.b a.a b.b 3)
Where b.b 1='4343' and b.b 2 in (select 2 from ta a.a where a a.a 1 and 1=b.b a.a 2=2 and 3=b.b a.a b.b 3)

The SQL so ugly ah, I feel a lot of conditions are repeated, so I wrote the following SQL
 merge into TB b 
Using (select a.a 1, a.a 2, 3, a.a sum (decode (a.a 4, '0', a.a 5, '1', (0 to 5) a.a, 0) tall from ta a group by 1, a.a a.a 2, and 3) a.a c)
On (b.b 1=1 and 2=2 and Arthur c. b.b Arthur c. b, b3=3 and Arthur c. b.b 1='4343')
The when matched then
Update the set b.b=b.b + c.t all

In the group of great god is there a better update statement, everybody,
  • Related