Multiple REPLACE function in Oracle(Oracle 中的多个 REPLACE 函数)
问题描述
我在 oracle 中使用 REPLACE 函数来替换我的字符串中的值;
I am using the REPLACE function in oracle to replace values in my string like;
SELECT REPLACE('THE NEW VALUE IS #VAL1#','#VAL1#','55') from dual
所以这可以替换一个值,但是如果超过 20 个,我应该使用 20 个以上的 REPLACE 函数还是有更实用的解决方案.
So this is OK to replace one value, but what about 20+, should I use 20+ REPLACE function or is there a more practical solution.
欢迎所有想法.
推荐答案
即使这个帖子很老也是 Google 上的第一个,所以我会使用正则表达式发布一个与此处实现的函数等效的 Oracle.
Even if this thread is old is the first on Google, so I'll post an Oracle equivalent to the function implemented here, using regular expressions.
比嵌套的 replace() 快得多,而且更干净.
Is fairly faster than nested replace(), and much cleaner.
在给定表的字符串列中将字符串 'a','b','c' 替换为 'd'
To replace strings 'a','b','c' with 'd' in a string column from a given table
select regexp_replace(string_col,'a|b|c','d') from given_table
它只不过是几个带有或"运算符的静态模式的正则表达式.
It is nothing else than a regular expression for several static patterns with 'or' operator.
注意正则表达式特殊字符!
Beware of regexp special characters!
这篇关于Oracle 中的多个 REPLACE 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Oracle 中的多个 REPLACE 函数
基础教程推荐
- 带有WHERE子句的LAG()函数 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
