split_token

NAME

split_token(): Return substring by index in delimited text.

TYPE

Function

DESCRIPTION

This function splits the input text txt into tokens, according to given delimiter_text. It returns a single token, indicated by the 1-based token_index.

The function is a shortcut to the common pattern of using two SUBSTRING_INDEX() invocations.

SYNOPSIS

split_token(txt TEXT CHARSET utf8, delimiter_text VARCHAR(255) CHARSET utf8, token_index INT UNSIGNED) 
  RETURNS TEXT CHARSET utf8

Input:

  • txt: text to be parsed. When NULL, the result is NULL.
  • delimiter_text: delimiter text; can be zero or more characters.
    When delimiter_text is the empty text (zero characters), function's result is the character in the position of token_index.
  • token_index: 1-based index. At current, there is no validation that given index is within tokenized text's bounds.

EXAMPLES

Tokenize by space:

mysql> SELECT common_schema.split_token('the quick brown fox', ' ', 3) AS token;
+-------+
| token |
+-------+
| brown |
+-------+

ENVIRONMENT

MySQL 5.1 or newer

SEE ALSO

get_num_tokens(), get_option()

AUTHOR

Shlomi Noach
 
common_schema documentation