【MySQL】substring_index 截取字符串函数详解
【MySQL】substring_index 函数详解
命令格式
string substring_index(string , string , int )
1
命令说明
截取字符串str第count个分隔符之前的字符串。如果count为正,则从左边开始截取。如果count为负,则从右边开始截取。此函数为MaxCompute 2.0扩展函数。
参数说明
str:必填。STRING类型。待截取的字符串。
separator:必填。STRING类型的分隔符。
count:必填。INT类型。指定分隔符位置。
返回值说明
返回STRING类型。如果任一输入参数值为NULL,返回NULL。
栗子1
示例1:截取字符串https://help.codingce.com。命令示例如下:
返回 https://help.codingce
select substring_index(‘https://help.codingce.com’, ‘.’, 2);
返回 codingce.com
下面展示一些 内联代码片
。
//# 返回 https://help.codingce
select substring_index('https://help.codingce.com', '.', 2);
//# 返回 codingce.com
select substring_index('https://help.codingce.com', '.', -2);
示例2:任一输入参数为NULL。命令示例如下:
返回NULL
select substring_index(‘https://help.codingce.com’, null, 2);
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_43874301/article/details/129516956