Programmer Guide : Scalar functions : String functions
  
String functions
This topic lists string manipulation functions.
Applications can call SQLGetInfo with the SQL_STRING_FUNCTIONS information type to determine which string functions are supported by a driver.
String function arguments
Arguments denoted as...
Definition
string_exp
These arguments 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.
start, length or count
These arguments can be a numeric literal or the result of another scalar function, where the underlying data type can be represented as SQL_TINYINT, SQL_SMALLINT, or SQL_INTEGER
character_exp
These arguments are a variable-length character string
The following string functions are 1-based, that is, the first character in the string is character 1, not character 0.
Note BIT_LENGTH, CHAR_LENGTH, CHARACTER_LENGTH, OCTET_LENGTH, and POSITION string scalar functions were added in ODBC 3.0 to align with SQL-92.
List of string functions
Function
Description
ASCII(string_exp)
(ODBC 1.0)
Returns the ASCII code value of the leftmost character of string_exp as an integer.
BIT_LENGTH(string_exp)
(ODBC 3.0)
Returns the length in bits of string expression.
CHAR(code)
(ODBC 1.0)
Returns the character that has the ASCII code value specified by code. The value of code should be between 0 and 255; otherwise, the return value is data source-dependent.
CHAR_LENGTH(string_exp)
(ODBC 3.0)
Returns the length in characters of the string expression, if the string expression is of a character data type; otherwise, returns the length in bytes of the string expression (the smallest integer not less than the number of bits divided by 8). (This function is the same as CHARACTER_LENGTH function.)
CHARACTER_LENGTH(string_exp)
(ODBC 3.0)
Returns the length in characters of the string expression, if the string expression is of a character data type; otherwise, returns the length in bytes of the string expression (the smallest integer not less than the number of bits divided by 8). (This function is the same as the CHAR_LENGTH function.)
CONCAT(string_exp1, string_exp2)
(ODBC 1.0)
Returns a character string that is the result of concatenating string_exp2 to string_exp1. The resulting string is DBMS-dependent.
DIFFERENCE(string_exp1, string_exp2)
(ODBC 2.0)
The function returns the difference between the soundex (see soundex function below) values of two character expressions, as an integer. The integer returned is the number of characters in the soundex values that are the same. The return value ranges from 0 through 4: 0 indicates little or no similarity, and 4 indicates strong similarity or identical values.
INSERT(string_exp1, start, length, string_exp2)
(ODBC 1.0)
Returns a character string where length characters have been deleted from string_exp1 beginning at start and where string_exp2 has been inserted into string_exp, beginning at start.
LCASE(string_exp)
(ODBC 1.0)
Returns a string equal to that string_exp, with all uppercase characters converted to lowercase.
LEFT(string_exp, count)
(ODBC 1.0)
Returns the leftmost count of characters of string_exp.
LENGTH(string_exp)
(ODBC 1.0)
Returns the number of characters in string_exp, excluding trailing blanks.
LOCATE(string_exp1, string_exp2[, start])
Returns the starting position of the first occurrence of string_exp1 within string_exp2. The search for the first occurrence of string_exp1 begins with the first character position in string_exp2 unless the optional argument, start, is specified. If start is specified, the search begins with the character position indicated by the value of start. The first character position in string_exp2 is indicated by the value 1. If string_exp1 is not found within string_exp2, the value 0 is returned.
If an application can call the LOCATE scalar function with the string_exp1, string_exp2, and start arguments, the driver returns
SQL_FN_STR_LOCATE when SQLGetInfo is called with an option of SQL_STRING_FUNCTIONS. If the application can call the LOCATE scalar function with only the string_exp1 and string_exp2 arguments, the driver returns SQL_FN_STR_LOCATE_2 when SQLGetInfo is called with an option of
SQL_STRING_FUNCTIONS. Drivers that support calling the LOCATE function with either two or three arguments return both SQL_FN_STR_LOCATE and SQL_FN_STR_LOCATE_2.
LTRIM(string_exp)
(ODBC 1.0)
Returns the characters of string_exp, with leading blanks removed.
OCTET_LENGTH(string_exp)
(ODBC 3.0)
Returns the length in bytes of the string expression. The result is the smallest integer not less than the number of bits divided by 8.
POSITION(character_exp IN character_exp)
(ODBC 3.0)
Returns the position of the first character expression in the second character expression. The result is an exact numeric with an implementation-defined precision and a scale of 0.
REPEAT(string_exp, count)
(ODBC 1.0)
Returns a character string composed of string_exp repeated count times.
REPLACE(string_exp1, string_exp2, string_exp3)
(ODBC 1.0)
Search string_exp1 for occurrences of string_exp2, and replace with string_exp3.
RIGHT(string_exp, count)
(ODBC 1.0)
Returns the rightmost count of characters of string_exp.
RTRIM(string_exp)
(ODBC 1.0)
Returns the characters of string_exp with trailing blanks removed.
SOUNDEX(string_exp1)
(ODBC 2.0)
Returns a character string containing the phonetic representation of the argument. This function lets you compare words that are spelled differently, but sound alike in English. If you supply a word to Soundex, it returns a 4-character phonetic code used by the U.S.Census Bureau since 1930s.
SPACE(count)
(ODBC 2.0)
Returns a character string consisting of count spaces.
SUBSTRING(string_exp, start, length)
(ODBC 1.0)
Returns a character string that is derived from string_exp, beginning at the character position specified by start for length characters.
TRIM(string_exp)
Returns the characters of string_exp with leading blanks and trailing blanks removed.
UCASE(string_exp)
(ODBC 1.0)
Returns a string equal to that in string_exp, with all lowercase characters converted to uppercase.
See also
Scalar functions