replace就是通常意义的字符串替换函数,而translate是一种字符替换函数,它是把每一个查找字符串中的字符替换成替换字符串中的对应字符.
下面是oracle官方对这2个函数的说明:
REPLACE
Syntax
Description of the illustration replace.gif
Purpose
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.
Both search_string
and replacement_string
, as well as char
, can be any of the datatypes CHAR
, VARCHAR2
, NCHAR
, NVARCHAR2
, CLOB
, or NCLOB
. The string returned is in the same character set as char
. The function returns VARCHAR2
if the first argument is not a LOB and returns CLOB
if the first argument is a LOB.
REPLACE
provides functionality related to that provided by the TRANSLATE
function. TRANSLATE
provides single-character, one-to-one substitution. REPLACE
lets you substitute one string for another as well as to remove character strings.
Examples
The following example replaces occurrences of J
with BL
:
SELECT REPLACE('JACK and JUE','J','BL') "Changes"
FROM DUAL;
Changes
--------------
BLACK and BLUE
TRANSLATE
Syntax
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, CLOB
s 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
<!---->
<!---->
*我的测试结果:
select replace('kkaxksx', 'kx', '12') from dual
结果:kkaxksx
select TRANSLATE('kkaxksx', 'kx', '12') from dual
结果:11a21s2
分享到:
相关推荐
4. **返回类型**:两者的返回类型根据输入类型不同而变化,但 `REPLACE` 可能返回 VARCHAR2 或 CLOB,而 `TRANSLATE` 总是返回与输入类型相同的值。 在实际使用中,根据具体需求选择合适的函数,如需进行简单的字符...
此函数提供了一些与 `translate` 函数相似的功能,但 `translate` 提供的是单字符一对一的替换,而 `replace` 允许用一个字符串替换另一个字符串,以及删除字符字符串。 #### 二、`translate` 函数 `translate` ...
**translate与replace的区别** - `translate`能够进行一对一的字符替换,并可以删除那些在`from_string`中有但`to_string`中没有的字符。 - `replace`则是替换整个子字符串,而不是单个字符,而且它不会删除字符,...
如果输出文件已经存在,则与现有字符串合并。安装在您的项目中安装软件包: npm install @biesbjerg/ngx-translate-extract --save-dev 将脚本添加到项目的package.json : ..." scripts " : { " i18n:init " : " ...
通过比较原字符串长度与替换后不包含 'E' 的字符串长度差,得到 'E' 的数量。 - **基本用法**: ```sql SELECT TRANSLATE('abcdefghij','abcdef','123456') FROM dual; SELECT TRANSLATE('abcdefghij','...
与`TRANSLATE`相比,它可以更灵活地处理复杂情况。 - **`REGEXP_REPLACE`语法**:`REGEXP_REPLACE(source_string, pattern, replacement[, start_position[, occurrence[, return_position]]])` - `source_string`...
总结起来,"Oracle替换"主要关注如何在Oracle数据库中对字符串进行查找和替换操作,包括标准的`REPLACE`函数,以及更复杂的`REGEXP_REPLACE`和`TRANSLATE`函数。同时,通过自定义的PL/SQL函数,开发者可以进一步定制...
在 MySQL 中,可以使用 `REGEXP_REPLACE` 函数,而在 Oracle 中,可以使用 `REGEXP_REPLACE` 函数或 `TRANSLATE` 函数。 在实际应用中,我们可能需要根据具体情况选择合适的方法。例如,如果我们只想将某些特殊字符...
《Python程序设计》基础知识及程序设计598题涵盖了Python语言的基础语法、字符串操作、正则表达式、列表、函数、编码与解码等多个方面。以下是根据题目内容提炼出的知识点: 1. 字符串方法:`replace()`用于替换...
这四个函数在用法上与 Oracle SQL 函数 LIKE、INSTR、SUBSTR 和 REPLACE 用法相同,但它们使用 POSIX 正则表达式代替了老的百分号(%)和通配符(_)字符。 POSIX 正则表达式由标准的元字符(metacharacters)所...
`strtr()`函数全称为“string translate”,它的作用是将字符串中的某些字符替换为其他字符。其基本语法是 `strtr(string, from, to)`,其中`string`是要进行转换的原始字符串,`from`是字符映射的源数组,`to`是...
在这个名为"word-translate"的项目中,我们似乎关注的是一个与文本处理和翻译相关的功能。下面将详细探讨JavaScript在实现字词翻译方面的应用及其相关知识点。 首先,JavaScript在网页交互中的核心地位使得它成为...
特别是在中文环境下,简体字与繁体字之间的转换需求日益增加。为了满足这种需求,开发了一种基于JavaScript的简繁体转换脚本。本文将详细介绍该脚本的工作原理及其各个组成部分的功能。 #### 二、核心概念 在深入...
TRANSLATE text USING 'ABBAabba'. => 'Abracadabra' ``` #### 九、日期格式转换 ```abap CONVERT DATE dat ``` - `dat` 是日期变量。 以上是ABAP中常用的字符串操作方法,涵盖了连接、分隔、查找、替换、格式...
在翻译姓名时,我们需要频繁地拼接、截取或替换字符串,例如使用`slice()`、`substring()`、`replace()`等方法。 2. **正则表达式**:在处理姓名格式时,正则表达式(Regular Expression)是不可或缺的工具。通过...
这与`TRANSLATE`相似,但`REPLACE`更灵活,可以替换任意长度的子串。 #### LOWER和UPPER函数 `LOWER`和`UPPER`函数分别用于将字符串转换为小写和大写。例如: ```sql SELECT LOWER(EMAIL), EMAIL FROM GINGERNAN_...
说明 ... [BaiduTranslate setupBaiduClientKey:@"REPLACE ME WITH KEY"]; BTResultBlock callback = ^(TranslationEntity *translation, NSError *error) { if (!error) { if (translation) {
new_text = translate_chars(text, chars_to_replace) print(new_text) # 输出:He\\110, w0r\\1d! ``` #### 方法四:使用正则表达式 如果需要进行更为复杂的模式匹配和替换操作,可以使用正则表达式模块`re`。...