Categories:
String & Binary Functions (General) , Semi-structured Data Functions (Conversion/Casting)

STRTOK_TO_ARRAY

Tokenizes the given string using the given set of delimiters and returns the tokens as an array.

If either parameter is a NULL, a NULL is returned. An empty array is returned if tokenization produces no tokens.

See also:
STRTOK

Syntax

STRTOK_TO_ARRAY(<string> [,<delimiter>])

Arguments

Required:

string
Text to be tokenized.

Optional:

delimiter
Set of delimiters. Optional. Default value is a single space character.

Returns

The data type of the returned value is ARRAY.

Examples

Here is a simple example of using STRTOK_TO_ARRAY to split a string into an array:

SELECT STRTOK_TO_ARRAY('a.b.c', '.');
+-------------------------------+
| STRTOK_TO_ARRAY('A.B.C', '.') |
|-------------------------------|
| [                             |
|   "a",                        |
|   "b",                        |
|   "c"                         |
| ]                             |
+-------------------------------+

This example tokenizes on multiple delimiters (‘.’ and ‘@’).

SELECT STRTOK_TO_ARRAY('user@snowflake.com', '.@');
+---------------------------------------------+
| STRTOK_TO_ARRAY('USER@SNOWFLAKE.COM', '.@') |
|---------------------------------------------|
| [                                           |
|   "user",                                   |
|   "snowflake",                              |
|   "com"                                     |
| ]                                           |
+---------------------------------------------+