substring_index
substring_index函数用于截取字符串str第count个分隔符之前的字符串。如果count为正,则从左边开始截取。如果count为负,则从右边开始截取。
命令格式
substring_index(string <str>, string <separator>, int <count>)
参数说明
| 
        参数  | 
      
        是否必选  | 
      
        参数类型  | 
      
        说明  | 
     
|---|---|---|---|
| 
        str  | 
      
        是  | 
      
        STRING  | 
      
        待截取的字符串。  | 
     
| 
        separator  | 
      
        是  | 
      
        STRING  | 
      
        STRING类型的分隔符。  | 
     
| 
        count  | 
      
        否  | 
      
        INT  | 
      
        指定分隔符位置。  | 
     
返回值说明
返回STRING类型。
 
   如果任一输入参数值为NULL,返回NULL。
示例代码
返回 hello.world。
SELECT substring_index('hello.world.people', '.', 2);  
  返回world.people。
select substring_index('hello.world.people', '.', -2);