Oracle-函数-替换字符串
REPLACE(char,search_string,replacement_string)
1991' is search_string '2001' is replacement_string REPLACE returns char with every occurrence of search_string replaced with replacement_string.
If replacement_string is omitted or null, then all occurrences of search_string are removed.
If search_string is null, then char is returned. REPLACE的实现是由TRANSLATE函数为基础,在REPLACE中,原值和被替换项与替换后的项数据类型支持:CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB
SELECT REPLACE('2301231991','1991','2001') FROM DUAL;
执行结果为:'2301232001'
TRANSLATE(char, from_string, to_string)
--' */''' is from_strin --'_' is to_string --被替换项从左至右依次替换,替换项按照使用个数递减,若替换项不足则替换为'' SELECT TRANSLATE('SQL*Plus User''s Guide', ' */''', '_') FROM DUAL; --执行结果为:SQLPlus_Users_Guide SELECT TRANSLATE('SQL*Plus User''s Guide', ' */''', '__') FROM DUAL; --执行结果为:SQL_Plus_Users_Guide SELECT TRANSLATE('SQL*Plus User''s Guide', ' */''', '___') FROM DUAL; --执行结果为:SQL_Plus_Users_Guide SELECT TRANSLATE('SQL*Plus User''s Guide', ' */''', '____') FROM DUAL; --执行结果为:SQL_Plus_User_s_Guide
REGEXP_REPLACE(source_char,match_parameter
,replace_string)
--REGEXP_REPLACE的实现是由REPLACE函数为基础,支持正则表达式,可以进行复杂字符处理 SELECT REGEXP_REPLACE('132.546.7890','([[:digit:]]{3})\.([[:digit:]]{3})\.([[:digit:]]{4})','(\1) \2-\3') FROM DUAL ; --The following example examines phone_number, looking for the pattern xxx.xxx.xxxx. Oracle reformats this pattern with (xxx) xxx-xxxx. --执行结果为:(132) 546-7890 SELECT REGEXP_REPLACE('500 Oracle Parkway, Redwood Shores, CA','( ){2,}', ' ') FROM DUAL; --The following example examines the string, looking for two or more spaces. Oracle replaces each occurrence of two or more spaces with a single space. --执行结果为:500 Oracle Parkway, Redwood Shores, CA
分类:
Oracle
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App