当前位置:网站首页>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'
边栏推荐
- Excel动态图制作
- CCF paper conference IEEE how to query all articles of a conference journal
- [kali-information collection] (1.8) ARP reconnaissance tool _Netdiscover
- AQS-AbstractQueuedSynchronizer
- 10份重磅报告 — 展望中国数字经济未来
- STM32+MPU6050设计便携式Mini桌面时钟(自动调整时间显示方向)
- 一体化在线政务服务平台,小程序容器技术加速建设步伐
- 5G网络切片技术
- CAN总线的AUTOSAR网络管理
- 流动性质押挖矿系统开发如何制作?单双币系统开发成熟技术
猜你喜欢
yolo格式(txt)数据集转VOC(xml)
有奖征集|TaoCloud&宝德联合举办全闪POC!
阿里云数据存储生态计划发布,助力伙伴数据创新
ASP.NET Core 6框架揭秘实例演示[31]:路由"高阶"用法
Problem solving in the process of using mosquitto
记一次mysql查询慢的优化历程
看我如何用多线程,帮助运营小姐姐解决数据校对系统变慢!
Multithreading (Basic) - 40,000 word summary
How to technically ensure the quality of LED display?
C#为listview选中的项添加右键菜单
随机推荐
大疆P4M云遮挡矫正
OLED的HAL库代码介绍及使用(stm32f1/I2C/HAL库版/100%一次点亮)
21 Days Learning Challenge - Day 1 Punch (Screen Density)
Failed to configure mysql, what's going on?
8大软件供应链攻击事件概述
爆款视频怎么做?这里或许有答案!
LeetCode每日一练 —— 225. 用队列实现栈
Geoffery Hinton: The Next Big Thing in Deep Learning
多线程(基础) - 4万字总结
Swift中什么时候不能用 () 代替 Void 来使用
C#/VB.NET 添加多行多列图片水印到Word文档
外包学生管理系统架构文档
Create a devops CI/CD process using the kubesphere GUI
Mysql事务隔离级别与MVCC(多版本并发控制)
【kali-信息收集】(1.9)Metasploit+搜索引擎工具Shodan
yolo格式(txt)数据集转VOC(xml)
jacoco的学习以及理解
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之一
leetcode: 200. 岛屿数量
The exchange - string dp