当前位置:网站首页>Character interception triplets of data warehouse: substrb, substr, substring
Character interception triplets of data warehouse: substrb, substr, substring
2022-06-28 00:03: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 allowed
CONTEXT: referenced column: substring
mysql_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 ~
边栏推荐
- Stream + Nacos
- Eliminate gaps around El image images
- Zero foundation self-study SQL course | case function
- 股市小白在网上股票开户安全吗?
- 夏日的晚会
- [VIM] tutorial, common commands, efficient use of vim editor
- Zero foundation self-study SQL course | complete collection of date functions in SQL
- c语言之字符串数组
- 零基础自学SQL课程 | IF函数
- 赛尔笔记|视频文本预训练简述
猜你喜欢

Zero foundation self-study SQL course | complete collection of SQL basic functions

What if Fiddler fails to listen to the interface

Structure de stockage des graphiques

Chenyun pytorch learning notes_ Build RESNET with 50 lines of code
![[PCL self study: Segmentation3] PCL based point cloud segmentation: region growth segmentation](/img/9e/f08ce0729c89b0205c0ac47c523ad7.png)
[PCL self study: Segmentation3] PCL based point cloud segmentation: region growth segmentation

Instructions for vivado FFT IP

Zero foundation self-study SQL course | case function

Cornernet由浅入深理解
![[tinyriscv verilator] branch transplanted to Da Vinci development board of punctual atom](/img/a8/4786e82d0646b08c195dd0a17af227.png)
[tinyriscv verilator] branch transplanted to Da Vinci development board of punctual atom
![Count prime [enumeration - > space for time]](/img/11/c52e1dfce8e35307c848d12ccc6454.png)
Count prime [enumeration - > space for time]
随机推荐
使用cef3开发的浏览器不支持flash问题的解决
How to use the apipost script - global variables
Mise en œuvre du pool de Threads: les sémaphores peuvent également être considérés comme de petites files d'attente
安全省油環保 駱駝AGM啟停電池魅力十足
QStringList 的学习笔记
flutter系列之:flutter中的变形金刚Transform
Excel print settings public header
【AI应用】NVIDIA GeForce RTX 1080Ti的详情参数
Zero foundation self-study SQL course | case function
What are the ways to combine the points system with marketing activities
Does the subscription of Siyuan notes stop deleting cloud data directly?
[microservices sentinel] sentinel data persistence
【PCL自学:Segmentation3】基于PCL的点云分割:区域增长分割
Chenyun pytorch learning notes_ Build RESNET with 50 lines of code
用两个栈实现队列[两次先进后出便是先进先出]
ICML 2022:ufrgs | optimistic linear support and subsequent features as the basis for optimal strategy transfer
N methods for obtaining effective length of genes
SQL报了一个不常见的错误,让新来的实习生懵了
c语言字符指针、字符串初始化问题
解决新版chrome跨域问题:cookie丢失以及samesite属性问题「建议收藏」