Mysql 通过解码更新查询
我有一张城市表,我必须用普纳代替印多尔,用印多尔代替普纳Mysql 通过解码更新查询,mysql,sql,oracle11g,Mysql,Sql,Oracle11g,我有一张城市表,我必须用普纳代替印多尔,用印多尔代替普纳 city output table ----- ------------ indore pune pune indore indore pune pune
city output table
----- ------------
indore pune
pune indore
indore pune
pune indore
indore pune
有两种方式,解码或大小写表达
1.使用解码
从表中选择城市、印多尔、普纳、普纳、印多尔、城市
2.用例
为什么要标记两个不同的RDBMS?因为我需要两个RDBMS中的解决方案可能的副本,我必须将indore替换为mumbai,将mumbai替换为indorei,我要更新表。如何将decode与udateUse合并语句一起使用。看看我的答案。 select case when city = 'indore' then 'pune' when city = 'pune' then 'indore' else city end
MERGE INTO table a
USING (
select city, decode(city, 'indore', 'pune', 'pune', 'indore', city) city_decode
from table) b
ON (a.city = b.city)
WHEN MATCHED
THEN
UPDATE SET a.city = b.city_decode
/