Scalar Functions

This section lists the scalar functions that ODBC supports. Your database system may not support all these functions. Refer to the documentation for your database system to find out which functions are supported. Also, depending on the driver that you are using, all the scalar functions may not be supported. To check which scalar functions are supported by a driver, use the SQLGetInfo ODBC function.

You can use these scalar functions in SQL statements using the following syntax:

{fn scalar-function} 

where scalar-function is one of the functions listed in Table 2-3 through Table 2-6. For example:

SELECT {fn UCASE(NAME)} FROM EMP 

String Functions

Table 2-3 lists the string functions that ODBC supports.

The string functions listed accept the following arguments:

The string functions are one-based; that is, the first character in the string is character 1.

Character string literals must be surrounded in single quotation marks.

Table 2-3. Scalar String Functions 
Function
Returns
ASCII(string_exp)
ASCII code value of the leftmost character of string_exp as an integer.
BIT_LENGTH(string_exp)
[ODBC 3.0 only]
The length in bits of the string expression.
CHAR(code)
The character with the ASCII code value specified by code. code should be between 0 and 255; otherwise, the return value is data-source dependent.
CHAR_LENGTH(string_exp)
[ODBC 3.0 only]
The length in characters of the string expression, if the string expression is of a character data type; otherwise, 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 CHARACTER_LENGTH function.)
CHARACTER_
LENGTH(string_exp)
[ODBC 3.0 only]
The length in characters of the string expression, if the string expression is of a character data type; otherwise, 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)
The string resulting from concatenating string_exp2 and string_exp1. The string is system dependent.
DIFFERENCE(string_exp1, string_exp2)
An integer value that indicates the difference between the values returned by the SOUNDEX function for string_exp1 and string_exp2.
INSERT(string_exp1, start, length, string_exp2)
A 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)
Uppercase characters in string_exp converted to lowercase.
LEFT(string_exp,count)
The count of characters of string_exp.
LENGTH(string_exp)
The number of characters in string_exp, excluding trailing blanks and the string termination character.
LOCATE(string_exp1, string_exp2[,start])
The starting position of the first occurrence of string_exp1 within string_exp2. If start is not specified, the search begins with the first character position in string_exp2. 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, 0 is returned.
LTRIM(string_exp)
The characters of string_exp with leading blanks removed.
OCTET_LENGTH(string_exp)
[ODBC 3.0 only]
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 only]
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)
A string composed of string_exp repeated count times.
REPLACE(string_exp1, string_exp2, string_exp3)
Replaces all occurrences of string_exp2 in string_exp1 with string_exp3.
RIGHT(string_exp, count)
The rightmost count of characters in string_exp.
RTRIM(string_exp)
The characters of string_exp with trailing blanks removed.
SOUNDEX(string_exp)
A data source dependent string representing the sound of the words in string_exp.
SPACE(count)
A string consisting of count spaces.
SUBSTRING(string_exp, start, length)
A string derived from string_exp beginning at the character position start for length characters.
UCASE(string_exp)
Lowercase characters in string_exp converted to uppercase.

Numeric Functions

Table 2-4 lists the numeric functions that ODBC supports.

The numeric functions listed accept the following arguments:

Date and Time Functions

Table 2-5 lists the date and time functions that ODBC supports.

The date and time functions listed accept the following arguments:

System Functions

Table 2-6 lists the system functions that ODBC supports.

Table 2-6. Scalar System Functions
Function
Returns
DATABASE()
Name of the database, corresponding to the connection handle (hdbc).
IFNULL(exp,value)
value, if exp is null.
USER()
Authorization name of the user.