15.00 - STRTOK_SPLIT_TO_TABLE - Teradata Database

Teradata Database SQL Functions, Operators, Expressions, and Predicates

Product
Teradata Database
Release Number
15.00
Content Type
Programming Reference
Publication ID
B035-1145-015K
Language
English (United States)
Last Update
2018-09-24

STRTOK_SPLIT_TO_TABLE

Purpose  

Splits strings into a table of tokens based on the provided delimiter(s) string.

Note: STRTOK_SPLIT_TO_TABLE has similar semantics to the standard C/C++ library STRTOK function.

Syntax  

where:

 

Syntax element …

Specifies …

TD_SYSFNLIB

the name of the database where the function is located.

inkey

a numeric or character argument.

instring

a character or CLOB argument.

If instring is NULL, the STRTOK_SPLIT_TO_TABLE returns NULL.

delimiters

a character argument.

If delimiters is not specified, the value defaults to a space character.

outkey

a numeric or character argument.

outkey is used to identify the instring in the result set.

tokennum

an integer.

tokennum is the ordinal position of the token in the input string.

token

a character argument.

The token from the input string is the same character set as instring.

ANSI Compliance

This is a Teradata extension to the ANSI SQL:2011 standard.

Invocation

STRTOK_SPLIT_TO_TABLE 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:

  • inkey = NUMERIC or VARCHAR
  • instring = VARCHAR(32000) or CLOB
  • delimiter = VARCHAR(64)
  • 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.

    Result Type

    The result row type is:

  • outkey = NUMERIC OR VARCHAR(10)
  • tokennum = INTEGER
  • token = VARCHAR(256)
  • Example  

    If:

    CREATE TABLE t (id integer, str varchar(256)character set unicode);
     

    and:

    INSERT INTO t VALUES (1,'Teradata-Warehouse 13.10 - Combine 2 powerful forms of business intelligence (BI).'); 
     

    and:

    insert into t values (2,'http://www.teradata.com/');
     

    then:

    SELECT d.* FROM TABLE (strtok_split_to_table(t.id, t.str, ' -/')
    RETURNS (outkey integer, tokennum integer, token varchar(20)character set unicode) ) as d order by 1,2;
     
     outkey   tokennum  token
    -----------  -----------  --------------------------
              1            1  Teradata
              1            2  Warehouse
              1            3  13.10
              1            4  Combine
              1            5  2
              1            6  powerful
              1            7  forms
              1            8  of
              1            9  business
              1           10  intelligence
              1           11  (BI).
              2            1  http:
              2            2  www.teradata.com