文档

SUBSTRING_INDEX

更新时间:

截取字符串strcount个分隔符之前的字符串。如果count为正,则从左边开始截取。如果count为负,则从右边开始截取。此函数为MaxCompute 2.0扩展函数。

命令格式

string substring_index(string <str>, string <separator>, int <count>)

参数说明

  • str:必填。STRING类型。待截取的字符串。

  • separator:必填。STRING类型的分隔符。

  • count:必填。INT类型。指定分隔符位置。

返回值说明

返回STRING类型。如果任一输入参数值为NULL,返回NULL。

使用示例

  • 示例1:截取字符串https://help.aliyun.com。命令示例如下。

    --返回https://help.aliyun。
    select substring_index('https://help.aliyun.com', '.', 2);
    --返回aliyun.com。
    select substring_index('https://help.aliyun.com', '.', -2);
  • 示例2:任一输入参数为NULL。命令示例如下。

    --返回NULL。
    select substring_index('https://help.aliyun.com', null, 2);

相关函数

SUBSTRING_INDEX函数属于字符串函数,更多查找字符串、转换字符串格式的相关函数请参见字符串函数

  • 本页导读 (1)
文档反馈