This topic describes how to use the string function SPLIT_INDEX in Realtime Compute.

Syntax

VARCHAR SPLIT_INDEX(VARCHAR str, VARCHAR sep, INT index)

Input parameters

Parameter Data type Description
str VARCHAR The source string that you want to split.
sep VARCHAR The separator that is used to split the string.
index INT The index of the substring that you want to extract from the source string.

Description

Uses the separator specified by sep to split the string specified by str into several substrings and returns the substring specified by index. The value of index starts from 0. If the substring with the specified index does not exist, null is returned. If any input parameter is set to null, null is returned.

Example

  • Test data
    str (VARCHAR) sep (VARCHAR) index (INT)
    Jack,John,Mary , 2
    Jack,John,Mary , 3
    Jack,John,Mary null 0
    null , 0
  • Test statements
    SELECT  SPLIT_INDEX(str, sep, index) as var1
    FROM T1;         
  • Test results
    var1 (VARCHAR)
    Mary
    null
    null
    null