博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Oracle TRANSLATE 函数
阅读量:5922 次
发布时间:2019-06-19

本文共 2454 字,大约阅读时间需要 8 分钟。

hot3.png

================原版官方解释==============================>

TRANSLATE ( 'expr' , 'from_string' , 'to_string' )

TRANSLATE returns expr with all occurrences of each character in from_string replaced by its corresponding character in to_string. Characters in expr that are not in from_string are not replaced. If expr is a character string, then you must enclose it in single quotation marks. The argument from_string can contain more characters than to_string. In this case, the extra characters at the end of from_string have no corresponding characters in to_string. If these extra characters appear in char, then they are removed from the return value.
You cannot use an empty string for to_string to remove all characters in from_string from the return value. Oracle Database interprets the empty string as null, and if this function has a null argument, then it returns null.
TRANSLATE provides functionality related to that provided by the REPLACE function. REPLACE lets you substitute a single string for another single string, as well as remove character strings. TRANSLATE lets you make several single-character, one-to-one substitutions in one operation.
This function does not support CLOB data directly. However, CLOBs can be passed in as arguments through implicit data conversion.
Examples
The following statement translates a book title into a string that could be used (for example) as a filename. The from_string contains four characters: a space, asterisk, slash, and apostrophe (with an extra apostrophe as the escape character). The to_string contains only three underscores. This leaves the fourth character in the from_string without a corresponding replacement, so apostrophes are dropped from the returned value.
SELECT TRANSLATE('SQL*Plus User''s Guide', ' */''', '___') FROM DUAL;
TRANSLATE('SQL*PLUSU
--------------------
SQL_Plus_Users_Guide
================粗略的汉字解释==============================>
TRANSLATE ( 'char' , 'from_string' , 'to_string' )
TRANSLATE返回将from_string中的每个字符替换为to_string中的相应字符以后的string。
TRANSLATE是REPLACE所提供的功能的一个超集。如果from_string比to_string长,那么在from_string中而不在to_string中的额外字符将从char中被删除,因为它们没有相应的替换字符。to_string不能为空。Oracle将空字符串解释为NULL,并且如果TRANSLATE中的任何参数为NULL,那么结果也是NULL。
举个例子--
select translate('123abc','2dc','4e') from dual;
因为from_string和to_string的位置是一一对应的,2对应4,d对应e,c没有对应的值,所以c应该会被删除。
所以例子的字符里的2会替换为4,
d因为字符串里没有,所以不作替换,
c由于没有对应的替换字符,所以字符串里的c会被删除
那么可以得出,结果是 143ab

转载于:https://my.oschina.net/placeholder/blog/164656

你可能感兴趣的文章
animation与transition区别
查看>>
Java Activiti 流程审批 后台框架源码 springmvc SSM 工作流引擎
查看>>
mysql之旅【第二篇】
查看>>
Linux —— 常见指令及其英文全称
查看>>
【嵌入式开发】ARM 芯片简介 (ARM芯片类型 | ARM处理器工作模式 | ARM 寄存器 | ARM 寻址)...
查看>>
XML数据库一睹为快
查看>>
javascript事件代理(Event Delegation)
查看>>
test
查看>>
放大镜查看大图代码
查看>>
10.25T3 时间复杂度 离线操作
查看>>
thinkphp自定义分类样式
查看>>
This text field does not specify an inputType or a hint
查看>>
RocketMQ源码 — 十、 RocketMQ顺序消息
查看>>
Monkey测试:Monkey的简单使用
查看>>
Ubuntu 12.04 相关问题
查看>>
mc01_IntelliJ IDEA安装与Java项目创建以及Tomcat配置
查看>>
Tomcat启动45秒解决问题
查看>>
beta 2
查看>>
[西安交大附中集训] 自积
查看>>
linux学习摘记
查看>>