sql - 如何仅替换 Oracle 中文本的某些部分?
问题描述
我正在尝试替换文本中的某些单词。但是,如果它是 url 的一部分,则不希望该词被替换。例如:技术一词。它在两个地方都替换了(包括 url)。
select regexp_replace('Part of the Technical Network Group https://technical.com/sites/',
'technical','tech',1,0,'i')
from dual
输出:
Part of the tech Network Group https://tech.com/sites/
预期输出:
Part of the tech Network Group https://technical.com/sites/
解决方案
分两步完成。
首先,如果单词出现在单词之间,其次如果单词是句子的第一个单词。
select
regexp_replace(regexp_replace('technical Part of Technical Group https://technical.com/sites/',
' technical',
' tech',1,0,'i'), 'technical ', 'tech ',1,0,'i')
from dual
希望这能解决您的问题。
推荐阅读
- bioinformatics - 蛋白质中原子的杂交(Biopython)
- php - 在子主题中覆盖父主题文件的问题
- vba - 如何在拆分数据库中为 SQL 字符串输入日期变量
- python - 如何设置双循环以从左上角到右下角扫描图像?
- recursion - StandardML 因子评估在 Poly/ML REPL 中进入无限循环
- java - Rest API ResponseEntity 为响应添加额外的属性
- r - list.files 考虑到 R 中的列表编号?
- reactjs - React Material UI Table/Data Grid 仅显示行但不显示列
- spring - 可以在 Rest Controller 中使用对象数组吗
- python - 在 Backtrader 问题中获取数据