当前位置:网站首页>Character interception triplets of data warehouse: substrb, substr, substring
Character interception triplets of data warehouse: substrb, substr, substring
2022-06-28 02:39:00 【Huawei cloud developer Alliance】
Abstract : Here are some usages and differences of these three functions in character interception .
This article is shared from Huawei cloud community 《GaussDB(DWS) The characters in are used to intercept triplets 》, author : I stand under the northern sky .
stay GaussDB(DWS) There is a function triplet in support of character interception function in , They are substrb()、substr()、substring(), Many people probably only know that they can manipulate string interception , It may not be very clear if we go deeper , Some are parameter truncation length 、 Some parameters are end positions 、 Some parameters can be negative 、 Some can't accept negative parameters ·····
Let's introduce some usages and differences of these three functions in character interception .
summary
substr,substrb,substring Are string interception functions , Can take two or three parameters , Used to extract a character of a specified length starting at a specified position in a string . The function is defined as follows :
Function form : substrb(string, from [, count]) substr(string, from [, count]) substring(string, from [, count]) Parameters to describe : From parameter string Extract substring from ,from Indicates the starting position of the extraction ,count Represents the length of the extracted substring . return type : textdifferences
1. Interception unit
substrb Intercept by byte ,substr/substring Intercept by character . With utf8 Coding, for example ,1 Chinese characters account for 3 Bytes , When using substrb Interception length 3 When you are in a string , Only one character can be intercepted , and substr/substring Three characters can be intercepted .

postgres=# select substrb('hwgs HUAWEI ',3,5),substr('hwgs HUAWEI ',3,5),substring('hwgs HUAWEI ',3,5); substrb | substr | substring---------+----------+----------- gs Hua | gs Huawei | gs Huawei (1 row)2. Interception rules
GaussDB(DWS) Currently, three compatibility modes are supported :ORA、TD and MySQL, Compatible with the function behavior of friends respectively , Improve the user migration experience . In different compatibility modes , The function difference is expressed as :
substrb(string, s[, n]): The behavior of each compatibility mode is consistent

postgres=# select substrb('hwgs HUAWEI ',5,3),substrb('hwgs HUAWEI ',8,3); substrb | substrb---------+--------- Hua | by (1 row)postgres=# select substrb('hwgs HUAWEI ',-6,3),substrb('hwgs HUAWEI ',-3,3); substrb | substrb---------+--------- Male | department (1 row)postgres=# select substrb('hwgs HUAWEI ',5,0),substrb('hwgs HUAWEI ',8,-1); substrb | substrb---------+--------- |(1 row)substr(string, s[, n]):s=0 There are compatible behavior differences

postgres=# select substr('hwgs HUAWEI ',5,3),substr('hwgs HUAWEI ',8,3); substr | substr--------+-------- Huawei | department (1 row)postgres=# select substr('hwgs HUAWEI ',0,3),substr('hwgs HUAWEI ',0,3); substr | substr--------+-------- hwg | hwg(1 row)mysql_db=# select substr('hwgs HUAWEI ',0,3),substr('hwgs HUAWEI ',0,3); substr | substr--------+-------- |(1 row)substring(string, s[, n]):s<=0 and n<0 There are compatible behavior differences

postgres=# select substring('hwgs HUAWEI ',0,3),substring('hwgs HUAWEI ',-1,3); substring | substring-----------+----------- hw | h(1 row)td_db=# select substring('hwgs HUAWEI ',0,3),substring('hwgs HUAWEI ',-1,3); substring | substring-----------+----------- hw | h(1 row)mysql_db=# select substring('hwgs HUAWEI ',0,3),substring('hwgs HUAWEI ',-1,3); substring | substring-----------+----------- | department (1 row)td_db=# select substring('hwgs HUAWEI ',0,-1);ERROR: negative substring length not allowedCONTEXT: referenced column: substringmysql_db=# select substring('hwgs HUAWEI ',0,-1); substring-----------(1 row)Summary
Sum up , Introduce and summarize in detail substrb()、substr()、substring() Differences and usages of , In daily use , If the intercepted string is a multi byte character , Or the interception parameter may be a special value , Then you should pay special attention ; This article , I hope I can help you !
Click to follow , The first time to learn about Huawei's new cloud technology ~
边栏推荐
- Dynamic Host Configuration Protocol
- Dynamic Host Configuration Protocol
- Data governance and data standards
- flask基础:模板继承+静态文件配置
- 数智学习|湖仓一体实践与探索
- Graduation summary
- 共阳极数码管真值表
- Cloud native (30) | kubernetes' app store Helm
- [2D code image correction and enhancement] simulation of 2D code image correction and enhancement processing based on MATLAB
- Exploration on the construction path of real-time digital warehouse integrating digital intelligence learning and streaming batch
猜你喜欢

Exploration on the construction path of real-time digital warehouse integrating digital intelligence learning and streaming batch

【二维码图像矫正增强】基于MATLAB的二维码图像矫正增强处理仿真

【历史上的今天】6 月 20 日:MP3 之父出生;富士通成立;谷歌收购 Dropcam

技术人员如何成为技术领域专家

图灵机启动顺序

【历史上的今天】6 月 16 日:甲骨文成立;微软 MSX 诞生;快速傅里叶变换发明者出生

Architecture high reliability application knowledge map ----- microservice architecture map

架构高可靠性应用知识图谱 ----- 架构演进之路

【历史上的今天】6 月 15 日:第一个手机病毒;AI 巨匠司马贺诞生;Chromebook 发布

Complex and inefficient logistics? Three steps to solve problems in enterprise administration
随机推荐
Opencv——几何空间变换(仿射变换和投影变换)
Flutter 使用 CustomPaint 绘制基本图形
Flask基础:模板渲染+模板过滤使用+控制语句
【历史上的今天】6 月 23 日:图灵诞生日;互联网奠基人出生;Reddit 上线
LeetCode - Easy - 197
【历史上的今天】6 月 10 日:Apple II 问世;微软收购 GECAD;发明“软件工程”一词的科技先驱出生
NER中BiLSTM-CRF解读Forward_algorithm
文件传输协议--FTP
The system administrator has set the system policy to prohibit this installation. Solution
【历史上的今天】6 月 17 日:术语“超文本”的创造者出生;Novell 首席科学家诞生;探索频道开播
SQL 注入绕过(五)
Redis~Geospatial(地理空间)、Hyperloglog(基数统计)
Opencv——霍夫变换以及遇到的一些问题
STM32F103的11个定时器
File transfer protocol --ftp
Complex and inefficient logistics? Three steps to solve problems in enterprise administration
共阳极数码管真值表
【历史上的今天】6 月 5 日:洛夫莱斯和巴贝奇相遇;公钥密码学先驱诞生;函数语言设计先驱出生
Is it safe for qiniu to open an account? How do I open an account online?
简单文件传输协议TFTP