8.3.17. TRIM()
Available in
DSQL, PSQL
Syntax
TRIM ([<adjust>] str)
<adjust> ::= {[<where>] [what]} FROM
<where> ::= BOTH | LEADING | TRAILING
Parameter | Description |
---|---|
str | An expression of a string type |
where | The position the substring is to be removed from — |
what | The substring that should be removed (multiple times if there are several matches) from the beginning, the end, or both sides of the input string str. By default it is space ( |
Result type
VARCHAR
or BLOB
Description
Removes leading and/or trailing spaces (or optionally other strings) from the input string. Since Firebird 2.1 this function fully supports text BLOB
s of any length and character set.
Examples
select trim (' Waste no space ') from rdb$database
-- returns 'Waste no space'
select trim (leading from ' Waste no space ') from rdb$database
-- returns 'Waste no space '
select trim (leading '.' from ' Waste no space ') from rdb$database
-- returns ' Waste no space '
select trim (trailing '!' from 'Help!!!!') from rdb$database
-- returns 'Help'
select trim ('la' from 'lalala I love you Ella') from rdb$database
-- returns ' I love you El'
select trim ('la' from 'Lalala I love you Ella') from rdb$database
-- returns 'Lalala I love you El'
Notes
If str is a
BLOB
, the result is aBLOB
. Otherwise, it is aVARCHAR(*n*)
with n the formal length of str.The substring to be removed, if specified, may not be bigger than 32767 bytes. However, if this substring is repeated at str‘s head or tail, the total number of bytes removed may be far greater. (The restriction on the size of the substring will be lifted in Firebird 3.)
When used on a |