当前位置:网站首页>数仓的字符截取三胞胎:substrb、substr、substring
数仓的字符截取三胞胎:substrb、substr、substring
2022-06-27 18:01:00 【InfoQ】
概述
函数形式:
substrb(string, from [, count])
substr(string, from [, count])
substring(string, from [, count])
参数描述:
从参数string中抽取子字符串,from表示抽取的起始位置,count表示抽取的子字符串长度。
返回值类型:
text差异
1. 截取单位

postgres=# select substrb('hwgs华为公司',3,5),substr('hwgs华为公司',3,5),substring('hwgs华为公司',3,5);
substrb | substr | substring
---------+----------+-----------
gs华 | gs华为公 | gs华为公
(1 row)2. 截取规则

postgres=# select substrb('hwgs华为公司',5,3),substrb('hwgs华为公司',8,3);
substrb | substrb
---------+---------
华 | 为
(1 row)
postgres=# select substrb('hwgs华为公司',-6,3),substrb('hwgs华为公司',-3,3);
substrb | substrb
---------+---------
公 | 司
(1 row)
postgres=# select substrb('hwgs华为公司',5,0),substrb('hwgs华为公司',8,-1);
substrb | substrb
---------+---------
|
(1 row)
postgres=# select substr('hwgs华为公司',5,3),substr('hwgs华为公司',8,3);
substr | substr
--------+--------
华为公 | 司
(1 row)
postgres=# select substr('hwgs华为公司',0,3),substr('hwgs华为公司',0,3);
substr | substr
--------+--------
hwg | hwg
(1 row)
mysql_db=# select substr('hwgs华为公司',0,3),substr('hwgs华为公司',0,3);
substr | substr
--------+--------
|
(1 row)
postgres=# select substring('hwgs华为公司',0,3),substring('hwgs华为公司',-1,3);
substring | substring
-----------+-----------
hw | h
(1 row)
td_db=# select substring('hwgs华为公司',0,3),substring('hwgs华为公司',-1,3);
substring | substring
-----------+-----------
hw | h
(1 row)
mysql_db=# select substring('hwgs华为公司',0,3),substring('hwgs华为公司',-1,3);
substring | substring
-----------+-----------
| 司
(1 row)
td_db=# select substring('hwgs华为公司',0,-1);
ERROR: negative substring length not allowed
CONTEXT: referenced column: substring
mysql_db=# select substring('hwgs华为公司',0,-1);
substring
-----------
(1 row)小结
边栏推荐
- Hanoi塔问题
- 带你认识图数据库性能和场景测试利器LDBC SNB
- 数组练习 后续补充
- Kotlin微信支付回调后界面卡死并抛出UIPageFragmentActivity WindowLeaked
- Implementation of reliable distributed locks redlock and redisson
- 实战回忆录:从Webshell开始突破边界
- Labelimg usage guide
- crontab的学习随笔
- 买股票在券商经理的开户链接上开户安全吗?求大神赐教
- Mathematical derivation from perceptron to feedforward neural network
猜你喜欢

MySQL初学者福利

Error reported by Huada MCU Keil_ Weak's solution

华大单片机KEIL报错_WEAK的解决方案

crontab的学习随笔

Embracing cloud Nativity: Practice of Jiangsu Mobile order center

“我让这个世界更酷”2022华清远见研发产品发布会圆满成功

爬取国家法律法规数据库

Comprehensively analyze the zero knowledge proof: resolve the expansion problem and redefine "privacy security"

Buzzer experiment based on stm32f103zet6 library function

Array exercises follow up
随机推荐
NVIDIA Clara-AGX-Developer-Kit installation
The Fifth Discipline: the art and practice of learning organization
International School of Digital Economics, South China Institute of technology 𞓜 unified Bert for few shot natural language understanding
MySQL初学者福利
Workflow automation low code is the key
MySQL beginner benefits
流程判断-三目运算-for循环
Blink SQL内置函数大全
crontab的学习随笔
爬取国家法律法规数据库
rust 中的结构体
海底电缆探测技术总结
SQL Server - Window Function - 解决连续N条记录过滤问题
Determine whether a variable is an array or an object?
Hanoi Tower problem
What is ICMP? What is the relationship between Ping and ICMP?
网络上开户买股票是否安全呢?刚接触股票,不懂求指导
UE4随笔:FString、FName 与 FText
判断一个变量是数组还是对象?
C# 二维码生成、识别,去除白边、任意颜色