注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Memory extender

Beautiful Day..

 
 
 

日志

 
 

TRANSLATE函数用法  

2011-08-08 17:12:35|  分类: SQL&PL/SQL |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
Translate函数,用来将字符串中某些字符替换为另外的字符,或删除某些字符,是逐一替换(和replace函数区别,replace的功能相当于word里面的查找替换,是以字符串整体来进行替换)。
也可以用来消除字符串中的某个或某些字符。
注:translate的to_string不能用NULL来打算将expr中的from_string全部消除掉,可以各加个相同的特殊字符来实现,否则会直接返回空。
例:SELECT TRANSLATE('trefds4321432142','/1234567890','/') FROM dual
将字符串中的数字全部消除掉,需以类似如上的做法来实现,加个'/'或其它特定字符
TRANSLATE(expr1,'/1234567890','/')这个可以用来判断 字符串expr1中是否全为数字,如果全为数字则返回空

SELECT TRANSLATE('what is this', 'ats ', '123_') FROM dual;
---------------------------------------------------------------------
wh12_i3_2hi3



附:

TRANSLATE

Syntax

Description of translate.gif follows
Description of the illustration translate.gif

Purpose

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.

See Also:

"Datatype Comparison Rules" for more information and REPLACE

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
  评论这张
 
阅读(554)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017