String functions
Db2 supports various string functions that are defined by ODBC using vendor escape clauses.
The following rules apply to input strings for these functions:
- Character string literals used as arguments to scalar functions must be enclosed in single quotes.
- Arguments denoted as string_exp can be the name of a column, a string literal, or the result of another scalar function, where the underlying data type can be represented as SQL_CHAR, SQL_VARCHAR, or SQL_LONGVARCHAR.
- Arguments denoted as start, length, code, or count can be a numeric literal or the result of another scalar function, where the underlying data type is integer based (SQL_SMALLINT, SQL_INTEGER).
- The first character in the string is considered to be at position 1.
- ASCII( string_exp )
- Returns the ASCII code value of the leftmost character of string_exp as an integer.
- CONCAT( string_exp1, string_exp2 )
- Returns a character string that is the result of concatenating string_exp2 to string_exp1.
- INSERT( string_exp1, start, length, string_exp2 )
- Returns a character string where length number of characters beginning at start is replaced by string_exp2 which contains length characters.
- LEFT( string_exp, count )
- Returns the leftmost count of characters of string_exp.
- LENGTH( string_exp )
- Returns the number of characters in string_exp, excluding trailing blanks and the string termination character.
- REPEAT( string_exp, count )
- Returns a character string composed of string_exp repeated count times.
- RIGHT( string_exp, count )
- Returns the rightmost count of characters of string_exp.
- SUBSTRING( string_exp, start, length )
- Returns a character string that is derived from string_exp beginning at the character position specified by start for length characters.