为什么
UPDATE Playlists
SET PlaylistName = replace(PlaylistName,'TDJ','TDJe'),
PlaylistName = replace(PlaylistName,'TDJe','TDJxxx')
未能取代TDJ?
考虑到我可能需要多次替换,那么什么是一个很好的紧凑修复?
答案 0 :(得分:0)
在UPDATE语句中,PlaylistName
右侧的任何列值(例如=
)都会出现原始值。
它等同于以下命令性代码:
for each row:
old = playlistName
new1 = replace(old,'TDJ','TDJe')
new2 = replace(old,'TDJe','TDJxxx')
playlistName = new1
playlistName = new2
尝试两次更新列是没有意义的。
您必须在单个表达式中进行所有替换:
UPDATE Playlists
SET PlaylistName = replace(replace(PlaylistName, 'TDJ', 'TDJe'), 'TDJe', 'TDJxxx')