8.5.4 LTRIM
Removes instances of the specified characters, starting from the beginning of the target character string.
Proceeding from the beginning of the character string, it removes all character that matches any of the characters targeted for removal, stopping as soon as it encounters a character that is not targeted for removal.
- Organization of this subsection
(1) Specification format
scalar-function-LTRIM ::= LTRIM(target-data[,chars-to-remove]) target-data ::= value-expression chars-to-remove ::= value-expression
(2) Explanation of specification format
- target-data:
-
Specifies the data to be deleted for the characters specified for erase-character.
The following specification rules apply:
-
Specify the target data in the form of a value expression. For details about value expressions, see 7.21 Value expression.
-
Specify CHAR, VARCHAR, or STRING type data for the target data.
-
You cannot specify a dynamic parameter by itself for the target data.
-
- erase-character:
-
Specifies the characters to delete from the target data.
The following specification rules apply:
-
Specify erase-character in the form of a value expression. For details about value expressions, see 7.21 Value expression.
-
Specify CHAR, VARCHAR, or STRING type data for erase-character.
-
If erase-character is omitted, its assumed value is a half-width space character.
-
If a dynamic parameter is specified by itself as erase-character, the assumed data type of the dynamic parameter will be VARCHAR(32000).
-
The following example illustrates the result of executing the scalar function LTRIM.
- Example:
-
LTRIM('1020rst201','012') → 'rst201'
LTRIM('aaaadatabaseaaaa','a') → 'databaseaaaa'
LTRIM('aabbccdatabase','abc') → 'database'
LTRIM('ΔΔΔdatabaseΔ') →'databaseΔ'
LTRIM('database','012') → 'database'
Legend: Δ: Half-width space
(3) Rules
-
The data type and data length of the execution result are shown in the following table.
Table 8‒14: Data type and data length of the execution result of the scalar function LTRIM Data type and data length of the target data
Data type and data length of the execution result
CHAR(n)
VARCHAR(n)
VARCHAR(n)
STRING
STRING
Legend: n: Maximum length of the target data
-
The NOT NULL constraint does not apply to the value of the execution result (the null value is allowed).
-
If target-data or chars-to-remove is the null value, the execution result will be the null value.
-
If the actual length of the target data is 0 bytes or 0 characters, the execution result will be data whose actual length is 0 bytes.
-
If all the target character string data is removed, the execution result will be data whose actual length is 0 bytes.
-
If you specify data whose actual length is 0 bytes or 0 characters for chars-to-remove, the execution result will be the target data.
(4) Example
- Example:
-
Remove the numeric prefix from the character string data in column C2 of table T1.
SELECT "C1",LTRIM("C2",'0123456789') FROM "T1"