background image

String Expressions

<< EXISTS Expressions | NULL Values >>
<< EXISTS Expressions | NULL Values >>

String Expressions

TABLE 27­4
String Expressions
Function Syntax
Return Type
CONCAT(String, String)
String
LENGTH(String)
int
LOCATE(String, String [, start])
int
SUBSTRING(String, start, length)
String
TRIM([[LEADING|TRAILING|BOTH] char) FROM] (String)
String
LOWER(String)
String
UPPER(String)
String
The CONCAT function concatenates two strings into one string.
The LENGTH function returns the length of a string in characters as an integer.
The LOCATE function returns the position of a given string within a string. It returns the first
position at which the string was found as an integer. The first argument is the string to be
located. The second argument is the string to be searched. The optional third argument is an
integer that represents the starting string position. By default, LOCATE starts at the beginning of
the string. The starting position of a string is 1. If the string cannot be located, LOCATE returns 0.
The SUBSTRING function returns a string that is a substring of the first argument based on the
starting position and length.
The TRIM function trims the specified character from the beginning and/or end of a string. If no
character is specified, TRIM removes spaces or blanks from the string. If the optional LEADING
specification is used, TRIM removes only the leading characters from the string. If the optional
TRAILING
specification is used, TRIM removes only the trailing characters from the string. The
default is BOTH, which removes the leading and trailing characters from the string.
The LOWER and UPPER functions convert a string to lower or upper case, respectively.
TABLE 27­5
Arithmetic Expressions
Function Syntax
Return Type
ABS(number)
int
, float, or double
MOD(int, int)
int
SQRT(double)
double
SIZE(Collection)
int
Full Query Language Syntax
Chapter 27 · The Java Persistence Query Language
757