get_num_tokens

NAME

get_num_tokens(): Return number of tokens in delimited text.

TYPE

Function

DESCRIPTION

Assumes given text txt is tokenized by given delimiter_text, and returns the number of tokens in the split text. Delimiter is assumed to be fixed text, of any length (not necessarily one character).

SYNOPSIS

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

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 number of characters in txt.
    When delimiter_text is not found in the text, function returns with 1.

EXAMPLES

Tokenize by space:

mysql> SELECT common_schema.get_num_tokens('the quick brown fox', ' ') AS num_tokens;
+------------+
| num_tokens |
+------------+
|          4 |
+------------+

Tokenize by non-existing delimiter:

mysql> SELECT common_schema.get_num_tokens('single', ',') AS num_tokens;
+------------+
| num_tokens |
+------------+
|          1 |
+------------+

ENVIRONMENT

MySQL 5.1 or newer

SEE ALSO

split_token()

AUTHOR

Shlomi Noach
 
common_schema documentation