sql替换函数匹配整个单词

发布于 2024-11-17 10:02:08 字数 225 浏览 5 评论 0原文

我希望替换字段中的一些文本,因此我有以下语句:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上芳菲 2024-11-24 10:02:08

您可以添加一个 WHERE 子句,这应该会让您非常接近:

...Your Current Query...
WHERE INV_DESCRIPTION LIKE '5ml%'
OR INV_DESCRIPTION LIKE '% 5ml%'

这只会更新以 5ml 开头或前面有空格的 5ml 的记录它,这将排除 15ml25ml 等。

这是假设 SQL Server。

You could add a WHERE clause which should get you pretty close:

...Your Current Query...
WHERE INV_DESCRIPTION LIKE '5ml%'
OR INV_DESCRIPTION LIKE '% 5ml%'

Which will only update records that start with 5ml or have 5ml with a space before it, which would exclude 15ml or 25ml, etc.

This is assuming SQL Server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文