NVP - Teradata Database

SQL Functions, Operators, Expressions, and Predicates

Product
Teradata Database
Release Number
15.00
Language
English (United States)
Last Update
2018-09-24
dita:id
B035-1145
lifecycle
previous
Product Category
Teradata® Database

NVP

Purpose  

Extracts the value of a name-value pair where the name in the pair matches the name and the number of the occurrence specified.

Syntax  

where:

 

Syntax element …

Specifies …

TD_SYSFNLIB

the name of the database where the function is located.

instring

the name-value pairs separated by multibyte delimiters.

name_to_search

the name whose instring value NVP returns.

name_delimiters

the multibyte delimiters used to separate name-value pairs.

Delimiters can contain any characters. They are separated from each other in the string by spaces. If a space is used as part of a delimiter, it must be escaped using a backslash (\). The maximum length of any delimiter is 10, and the maximum size of this parameter is 32.

This parameter is optional and if not specified, the default value is & ampersand).

value_delimiters

the multibyte delimiters used to associate a name to its value in a name-value pair.

Delimiters can contain any characters. They are separated from each other in the string by spaces. If a space is used as part of a delimiter, it must be escaped using a backslash (\). The maximum length of any delimiter is 10, and the maximum size of this parameter is 32.

This parameter is optional and if not specified, the default value is = (equal sign).

occurrence

the number of occurrences of name_to_search that NVP searches for.

This parameter is optional and if not specified, the default value is 1.

ANSI Compliance

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

Invocation

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

  • instring = VARCHAR or CLOB
  • name_to_search = VARCHAR
  • name_delimiters = VARCHAR
  • value_delimiters = VARCHAR
  • occurrence = INTEGER
  • The character set of instring, name_to_search, name_delimiters, and value_delimiters can be LATIN or UNICODE. If the parameter character sets are mixed, then all the parameters will be converted to UNICODE.

    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.

    If a delimiter is part of a longer delimiter, the longer delimiter has precedence in the matching process.

    Adjacent delimiters are treated as a single delimiter.

    Result Type

    The result data type is VARCHAR with the same character set as that of instring.

    Example  

    The following query:

    SELECT NVP ('entree:orange chicken#entree2:honey salmon', 'entree','#', ':', 1);

    returns 'orange chicken'.

    Example  

    The following query:

    SELECT NVP('store = whole foods&&store: ?Bristol farms','store', '&&', '\ =\  :\ ?', 2);

    returns 'Bristol farms'.

    In this example, occurrence = 2 instructs NVP to search for the second occurrence of 'store'.

    Example  

    The following query:

    SELECT NVP('entree=orange chicken&entree2=honey salmon', 'entree', 1)

    returns 'orange chicken'.

    In this example, name_delimiters is & (default value) and value_delimiters is = (default value).

    Example  

    The following query:

    SELECT NVP('entree=orange chicken&entree2=honey salmon', 'entree');

    returns 'orange chicken'.

    In this example, name_delimiters is & (default value), value_delimiters is = (default value), and occurrence is 1 (default value).