Fixed Character Columns
The TRIM function can be specified on fixed-length character columns. If the length of the string is not completely filled, the unused characters are padded with blank space. Column Entry in a Fixed-Length Character Column shows this concept for the column entry '
##A2T##
', where the column is defined as CHAR(10).
If you want to trim the sharp sign ( # ) pad_char from the column, you need to consider the blank padded spaces as well as the actual characters.
For example, if you specify the keyword BOTH, the result from the trim operation is
A2T##
, because the TRIM function does not match the blank padded space that follows the string. In this case, the only sharp signs ( # ) trimmed are those that precede the other characters. The SELECT statement is shown, followed by Result of TRIM Operation, which presents the result.
SELECT TRIM(LEADING '#' FROM col1) FROM taba;
This SELECT statement removes all occurrences of the sharp ( # ) sign:
SELECT TRIM(BOTH '#' FROM TRIM(TRAILING ' ' FROM col1)) FROM taba;