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 函数
基础教程推荐
- 无法解决整理冲突 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
