String functions perform conversion, extraction, or manipulation operations on strings or return information about strings.
When working in a multibyte character set, check carefully whether the function being used returns information concerning characters or bytes.
Most of the string functions accept binary data (hexadecimal strings) in the string-expr parameter, but some of the functions, such as LCASE, UCASE, LOWER, and LTRIM, expect the string expression to be a character string.
Table 5-4 lists all string functions and their parameters.
String function |
Parameters |
---|---|
ASCII |
( string-expr ) |
BIT_LENGTH |
( column-name ) |
BYTE_LENGTH |
( string-expr ) |
CHAR |
( integer-expr ) |
CHAR_LENGTH |
( string-expr ) |
CHARINDEX |
( string-expr1, string-expr2 ) |
DIFFERENCE |
( string-expr1, string-expr2 ) |
INSERTSTR |
( numeric-expr, string-expr1, string-expr2 ) |
LCASE |
( string-expr ) |
LEFT |
( string-expr, numeric-expr ) |
LENGTH |
( string-expr ) |
LOCATE |
( string-expr1, string-expr2 [, numeric-expr ] ) |
LOWER |
( string-expr ) |
LTRIM |
( string-expr ) |
OCTET_LENGTH |
( column-name ) |
PATINDEX |
( '%pattern%', string_expr ) |
REPEAT |
( string-expr, numeric-expr ) |
REPLACE |
( original-string, search-string, replace-string ) |
REPLICATE |
( string-expr, integer-expr ) |
RIGHT |
( string-expr, numeric-expr ) |
RTRIM |
( string-expr ) |
SIMILAR |
( string-expr1, string-expr2 ) |
SORTKEY |
( string_expr [ collation-name ] ) |
SOUNDEX |
( string-expr ) |
SPACE |
( integer-expr ) |
STR |
( numeric_expr [, length [, decimal ] ] ) |
STRING |
( string1 [, string2, ..., string99 ] ) |
STUFF |
( string-expr1, start, length, string-expr2 ) |
SUBSTRING |
( string-expr, integer-expr [, integer-expr ] ) |
TRIM |
( string-expr ) |
UCASE |
( string-expr ) |
UPPER |
( string-expr ) |