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;

相关文章

Java Oracle 结果集是Java语言中处理数据库查询结果的一种方...
Java AES和Oracle AES是现代加密技术中最常使用的两种AES加密...
Java是一种广泛应用的编程语言,具备可靠性、安全性、跨平台...
随着移动互联网的发展,抽奖活动成为了营销活动中不可或缺的...
Java和Oracle都是在计算机领域应用非常广泛的技术,他们经常...
Java 是一门非常流行的编程语言,它可以运行于各种操作系统上...