sql替换函数匹配整个单词
我希望替换字段中的一些文本,因此我有以下语句:
UPDATE INVENTORY
SET INV_DESCRIPTION = REPLACE(INV_DESCRIPTION, '5 ml', '5ml (1/6oz)')
问题在于该语句将用替换字符串替换诸如 '5 ml' '15 ml' '150 ml' 等字符串。我希望这个函数能够匹配整个单词并只查找“5 ml”
I wish to replace some text within a field, so i have the following statement:
UPDATE INVENTORY
SET INV_DESCRIPTION = REPLACE(INV_DESCRIPTION, '5 ml', '5ml (1/6oz)')
The problem lies in the fact that this statement will replace strings such as '5 ml' '15 ml' '150 ml' etc, with the replacement string. I wish for this function to match the whole word and just look for '5 ml'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以添加一个
WHERE
子句,这应该会让您非常接近:这只会更新以
5ml
开头或前面有空格的5ml
的记录它,这将排除15ml
或25ml
等。这是假设 SQL Server。
You could add a
WHERE
clause which should get you pretty close:Which will only update records that start with
5ml
or have5ml
with a space before it, which would exclude15ml
or25ml
, etc.This is assuming SQL Server.