sql替换整个单词的函数 [英] sql replace function that matches whole words
本文介绍了sql替换整个单词的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望替换字段中的某些文本,因此我有以下声明:
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)')
问题在于,该语句将用替换字符串替换字符串,例如'5 ml''15 ml''150 ml'等.我希望此功能能够匹配整个单词,只是寻找"5 ml"
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'
推荐答案
您可以添加WHERE
子句,该子句可以使您更加接近:
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%'
只会更新以5ml
开头或以5ml
开头的空格(不包括15ml
或25ml
等)的记录.
Which will only update records that start with 5ml
or have 5ml
with a space before it, which would exclude 15ml
or 25ml
, etc.
这是假设使用SQL Server.
This is assuming SQL Server.
这篇关于sql替换整个单词的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文