Oracle Translate & Replace

点击打开链接

Oracle Translate & Replace
Version 11.1
Note:Translate and replace are very similar in their appearance but can produce very different results. Translate replaces by position,the first character of the list to match is replaced by the first character of the replacement list. The second character with the second,and if there are characters in the list to match that do not have positional equivalents in the replacements list they are dropped.

Replace replaces the string to match with the replacement string. The replacement of a single character is the same as that ofTRANSLATE.
Syntax TRANSLATE(
str1VARCHAR2CHARACTER SET ANY_CS,
srcVARCHAR2CHARACTER SET STR1%CHARSET,
destVARCHAR2CHARACTER SET STR1%CHARSET)
RETURNVARCHAR2CHARACTER SET STR1%CHARSET;
Translate Built-in String Function
Single Character
Replacement
TRANSLATE(<string>,<'list_to_match'>,<'replacements_list'>)

This demo replaces all commas with vertical bars.
SELECTTRANSLATE('comma,delimited,list',',','|')
FROMDUAL;
Multiple Character
Replacement
The following takes a DNA sequence and returns its complement
SELECTTRANSLATE('CAG-TTT-GAC-ACA-TGG-ATC','ACGT','GATC') DNA
FROMDUAL;
Character Replacement
And Elimination
The a is replaced with an e,the h has no complement and is dropped.
SELECTTRANSLATE('So What','ah','e')
FROMDUAL;
Eliminating Double
Quotes
Capital A is replaced with capital A. The double quote is eliminated because there is no match.
SELECTTRANSLATE('"Darn double quotes"','A"','A')
FROMDUAL;
Encryption / Decryption In this demo a string is first encrypted then decrypted
SELECTTRANSLATE('this is a secret',
'abcdefghijklmnopqrstuvxyz','0123456789qwertyuiop[kjhbv')
FROMDUAL;

SELECTTRANSLATE('p78o 8o 0 o42i4p',
'0123456789qwertyuiop[kjhbv','abcdefghijklmnopqrstuvxyz')
FROMDUAL;
Counting Vowels In this demo the number of vowels in the string is counted
WITH dataAS(SELECT'Whose line is it anyway' lineFROMDUAL)
SELECTLENGTH(line)-LENGTH(TRANSLATE(line,'xaeIoU','x')) nbVowels
FROMdata;
Replace Built-in String Function
REPLACE (overload 1) REPLACE(
srcstrVARCHAR2CHARACTER SET ANY_CS,
oldsubVARCHAR2CHARACTER SET SRCSTR%CHARSET,
newsubVARCHAR2CHARACTER SET SRCSTR%CHARSET := NULL)
RETURNVARCHAR2CHARACTER SET SRCSTR%CHARSET;
REPLACE (overload 2) REPLACE(
srcstrCLOBCHARACTER SET ANY_CS,
oldsubCLOBCHARACTER SET SRCSTR%CHARSET,
newsubCLOBCHARACTER SET SRCSTR%CHARSET := NULL)
RETURNCLOBCHARACTER SET SRCSTR%CHARSET;
Single Character
Replacement
REPLACE(<string>,<'string_to_match'>,<'replacements_string'>)
SELECTREPLACE('So What','o','ay')
FROMDUAL;
Multiple Character
Replacement
Replacement of a single character with a phrase
SELECTREPLACE('An ideathat is not dangerous is unworthy of being called an ideaat all.','n idea','software program') TRUTH
FROMDUAL;

相关文章

数据库版本:11.2.0.4 RAC(1)问题现象从EM里面可以看到,在23号早上8:45~8:55时,数据库等待会话暴增...
(一)问题背景最近在对一个大约200万行数据的表查看执行计划时,发现存在异常,理论上应该返回100多万...
(一)删除备份--DELETE命令用于删除RMAN备份记录及相应的物理文件。当使用RMAN执行备份操作时,会在RM...
(1)DRA介绍 数据恢复顾问(Data Recovery Advise)是一个诊断和修复数据库的工具,DRA能够修复数据文...
RMAN(Recovery Manager)是Oracle恢复管理器的简称,是集数据库备份(backup)、修复(restore)和恢复...
(1)备份对象 可以使用RMAN进行的备份对象如下: --整个数据库:备份所有的数据文件和控制文件; --数...