Splits instring into tokens based on the specified list of delimiter characters and returns the nth token, where n is specified by the tokennum argument.
the name of the database where the function is located.
a character string or string expression.
a list of delimiter characters. Each character in the string is considered a delimiter character.
If not specified, the default delimiter character is a space character.
the ordinal token to return.
If not specified, the default value is 1.
This is a Teradata extension to the ANSI SQL:2011 standard.
STRTOK is an embedded services system function. For information on activating and invoking embedded services functions, see “Embedded Services System Functions” on page 24.
Argument Types and Rules
Expressions passed to this function must have the following data types:
You can also pass arguments with data types that can be converted to the above types using the implicit data type conversion rules that apply to UDFs.
Note: The UDF implicit type conversion rules are more restrictive than the implicit type conversion rules normally used by Teradata Database. If an argument cannot be converted to the required data type following the UDF implicit conversion rules, it must be explicitly cast.
For details, see “Compatible Types” in SQL External Routine Programming.
The result data type is VARCHAR and the character set is the same as that of the instring argument. For example, if the instring argument has a data type of VARCHAR CHARACTER SET UNICODE, the result data type is VARCHAR CHARACTER SET UNICODE.
STRTOK has similar semantics as the standard C/C++ library STRTOK function.
If instring contains fewer tokens than tokennum, the function returns a zero-length string.
If either instring or delimiter is NULL, the function returns NULL.
Consider the following table and inserted data.
CREATE TABLE t (id INTEGER, str VARCHAR(256));
INSERT INTO t VALUES (1,'Teradata-Warehouse 13.10 - Combine 2 powerful forms of business intelligence (BI).');
INSERT INTO t VALUES (2,'http://www.teradata.com/');
The following query returns the 3rd token from the t.str string value. There are only 2 tokens in the second string, so the function returns a zero-length string for that row.
SELECT id, STRTOK(t.str, ' -/', 3) FROM t;
The output from the query is: