当前位置:网站首页>Character interception triplets of data warehouse: substrb, substr, substring
Character interception triplets of data warehouse: substrb, substr, substring
2022-06-27 20:23:00 【51CTO】
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 :
text
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
differences
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 .
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)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
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)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
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)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
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 ~
边栏推荐
- Accumulating power in the middle stage, UFIDA IUAP builds a new base for digital intelligence of social enterprises
- 移动低代码开发专题月 | 可视化开发 一键生成专业级源码
- 安装NFS服务
- 安全才是硬道理,沃尔沃XC40 RECHARGE
- Backtracking related issues
- Linux system plays Oracle database multi table query connection query with a smile
- SQL reported an unusual error, which confused the new interns
- Data intelligence enters the "deep water area", and data governance is the key
- Data intelligence enters the "deep water area", and data governance is the key
- 键入网址到网页显示,期间发生了什么?
猜你喜欢
Postman Chinese tutorial (postman Chinese version)
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
云原生存储解决方案Rook-Ceph与Rainbond结合的实践
Grasp the detailed procedure of function call stack from instruction reading
安全才是硬道理,沃尔沃XC40 RECHARGE
[login interface]
UE4 realizes long press function
308. 二维区域和检索 - 可变 线段树/哈希
Connection integration development theme month | drivers of enterprise master data governance
【debug】平台工程接口调试
随机推荐
Is the account opening QR code given by CICC securities manager safe? Who can I open an account with?
Oracle 架构汇总
Array exercises follow up
Batch insert data using MySQL bulkloader
Logcli-loki 命令行工具
Enumeration and control flow operation in rust
1029 Median
Rust 中的枚举和控制流运算
Database log
散列表(Hash)-复习
BAIC makes a brand new pickup truck, which is safe and comfortable
UE4随笔:FString、FName 与 FText
数据库锁问题
Hash table - Review
ABAP-SM30删除前检查
蓄力中台,用友iuap筑牢社会级企业数智化新底座
Redis集群
Graylog 新一代日志收集预警系统安装配置
Doctoral Dissertation of the University of Toronto - training efficiency and robustness in deep learning
数据库事务