[英]SQL string replace wildcard
I have a table X with column Y, that contains text like this: 我有一个带有Y列的表X,其中包含如下文本:
Click <a href=""http://www.stackoverflow.com"">here</a> to redeem
I need it turned into: 我需要它变成:
Click <a href="http://www.stackoverflow.com">here</a> to redeem
ie. 即。 remove the extra pair of quotes 删除额外的一对报价
The text outside of the ""url"" may be anything. “url”之外的文本可能是任何内容。
Is it something like this? 这是这样的吗?
Update X SET Y = REPLACE(Y, '""%""', '"%"' );
REPLACE
用第3个参数替换第2个参数的所有出现:
update X set Y = replace(Y, '""', '"')
select replace('Click <a href=""http://www.stackoverflow.com"">here</a> to redeem','""','"')
在实际进行更新之前,我使用select来检查更新的内容。
你需要用“”代替“,所以这样做:
Update X SET Y = REPLACE(Y, '""', '"')
You need to replace "" by ", so do it like this: 你需要用“”代替“,所以这样做:
Update X SET Y = REPLACE(Y, '""', '"') WHERE y LIKE '""%""';
Use with a dose of caution, because it will also replace text like: 谨慎使用,因为它也会替换以下文字:
Click <a href="http://www.stackoverflow.com">""here""</a> to redeem
into 成
Click <a href="http://www.stackoverflow.com">"here"</a> to redeem
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.