文档

LOCATE

更新时间:

str中查找substr的位置。您可以通过start_pos指定开始查找的位置,从1开始计数。

命令格式

bigint locate(string <substr>, string <str>[, bigint <start_pos>]) 

参数说明

  • substr:必填。STRING类型。待查找的字符串。

  • str:必填。STRING类型。待匹配的字符串。

  • start_pos:可选。BIGINT类型。指定查找的起始位置。

返回值说明

返回为BIGINT类型。返回规则如下:

  • str中无法匹配到substr时,返回0。

  • strsubstr值为NULL时,返回NULL。

  • start_pos值为NULL时,返回0。

使用示例

  • 示例1:查找字符串ab在字符串abchelloabc中的位置。命令示例如下。

    --返回1。
    select locate('ab', 'abchelloabc');
  • 示例2:查找字符串hi在字符串abchelloabc中的位置。命令示例如下。

    --返回0。
    select locate('hi', 'abc,hello,ab,c');
  • 示例3:start_pos为NULL。命令示例如下。

    --返回0。
    select locate('ab', 'abhelloabc', null);

相关函数

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

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