当前位置:网站首页>SQL function $TRANSLATE
SQL function $TRANSLATE
2022-08-02 11:35:00 【User 7741497】
SQL function $TRANSLATE
A string function that performs character-by-character replacement.
Outline
$TRANSLATE(string,identifier[,associator])
parameter
string
- the target string.It can be a field name, literal, host variable, or SQL expression.identifier
- The character to search for in the string.It can be a string or numeric literal, host variable, or SQL expression.associator
- optional - replacement characters corresponding to each character in the identifier.It can be a string or numeric literal, host variable, or SQL expression.
Description
The$TRANSLATE
function performs character-by-character substitution in the return value string.It processes string arguments one character at a time.It compares each character in the string with each character in the identifier parameter.If $TRANSLATE
finds a match, it notes the position of that character.
- The two-argument form of
$TRANSLATE
removes all instances of characters in the identifier argument from the output string. The three-argument form of $TRANSLATE
replaces all instances of each identifier character found in the string with the associated character corresponding to the position.Replacement is performed based on characters, not strings.If the identifier parameter contains more characters than the associated parameter, the extra characters in the identifier parameter are removed from the output string.If the identifier parameter contains fewer characters than the associated parameter, the extra characters in the associated parameter are ignored.
$TRANSLATE
is case sensitive.
$TRANSLATE
cannot be used to replace NULL
with a character.
If too few parameters are specified, SQLCODE -380
will be issued.If too many parameters are specified, SQLCODE -381
is issued.
$TRANSLATE and REPLACE
$TRANSLATE
performs character-by-character matching and replacement.REPLACE
performs string-to-string matching and replacement.REPLACE
can replace a single specified substring of one or more characters with another substring, or delete multiple instances of a specified substring.$TRANSLATE
can replace multiple specified characters with the corresponding specified replacement characters.
By default, both functions are case-sensitive, start at the beginning of the string, and replace all matching instances.REPLACE
has parameters that can be used to change these defaults.
Example
In the following example, the two parameters $TRANSLATE
modify the name value by removing punctuation (comma, space, period, apostrophe, hyphen), returning a name that contains only alphabetic characters.Note that identifiers double the apostrophe to escape it as a literal character, not a string delimiter:
SELECT TOP 20 Name,$TRANSLATE(Name,', .''-') AS AlphaNameFROM Sample.PersonWHERE Name %STARTSWITH 'O'
In the following example, the three-argument $TRANSLATE
modifies the name value by replacing commas and spaces with caret (^
) characters, returning a three-part delimitedFirst name (last name, first name, middle initial).Note that the linker must specify “^”
as many times as there are characters in the identifier:
SELECT TOP 20 Name,$TRANSLATE(Name,', ','^^') AS PiecesNamePuncFROM Sample.PersonWHERE Name %STARTSWITH 'O'
In the following example, the three-parameter $TRANSLATE
is specified by replacing commas and spaces with caret (^
) characters (specified in identifiers and ligators) andRemove periods, apostrophes and hyphens (specified in identifiers, from associated persons):
SELECT TOP 20 Name,$TRANSLATE(Name,', .''-','^^') AS PiecesNameNoPuncFROM Sample.PersonWHERE Name %STARTSWITH 'O'
边栏推荐
- 小程序插件让开发者受益的几个理由
- yolo格式(txt)数据集转VOC(xml)
- 记一次mysql查询慢的优化历程
- npm run serve启动报错npm ERR Missing script “serve“
- Deep Learning 100 Examples - Convolutional Neural Network (CNN) for mnist handwritten digit recognition
- [kali-information collection] (1.8) ARP reconnaissance tool _Netdiscover
- 2022年8月初济南某外包公司全栈开发面试题整理
- Challenge LeetCode1000 questions in 365 days - Day 047 Design Circular Queue Circular Queue
- The sitcom "Re-Walking the Long March" was staged
- Problem solving in the process of using mosquitto
猜你喜欢
【Acunetix-忘记密码】
Axure谷歌浏览器扩展程序下载及安装方法(免翻墙)
Crack detection technology based on deep learning
The exchange - string dp
雷克萨斯,锁死的安全,挡不住的心寒
ssm web page access database data error
Mysql transaction isolation level and MVCC (multi-version concurrency control)
ssm网页访问数据库数据报错
打破千篇一律,DIY属于自己独一无二的商城
一体化在线政务服务平台,小程序容器技术加速建设步伐
随机推荐
ansible模块--copy模块
npm WARN deprecated [email protected] This version of tar is no longer supported, and will not receive
Failure Analysis | A SELECT statement crashes MySQL, what happened?
企业级数据治理工作怎么开展?Datahub这样做
go语言的接口
华为eNSP(基础实验通信)
Running yum reports Error: Cannot retrieve metalink for reposit
【kali-信息收集】(1.8)ARP侦查工具_Netdiscover
保姆级教程:写出自己的移动应用和小程序(篇二)
ssm网页访问数据库数据报错
Camera Hal OEM模块 ---- cmr_snapshot.c
QT笔记——在一个窗口上显示另外一个透明窗口
[kali-information collection] (1.9) Metasploit + search engine tool Shodan
受邀出席Rust开发者大会|Rust如何助力量化高频交易?
Kotlin的协程与生命周期
Three.JS程序化建模入门
记录代码
jvmxmx和xms参数分析(设定优化校准)
SQL(面试实战07)
Challenge LeetCode1000 questions in 365 days - Day 047 Design Circular Queue Circular Queue