The LENGTH() function
Informix®
Informix provides the LENGTH()
function to count the number of bytes of a character string expression:
SELECT LENGTH("aaa"), LENGTH(col1) FROM table
Informix LENGTH()
does not count the
trailing blanks for CHAR
or VARCHAR
expressions, while Oracle
counts the trailing blanks.
Informix LENGTH()
returns 0 when the
given string is empty. That means, LENGTH('')=0
.
IBM® DB2®
IBM DB2 supports the
LENGTH()
function, but there are some differences with Informix LENGTH()
.
The IBM DB2
LENGTH()
function counts trailing blanks. When using a CHAR
column, values are blank padded, and the function returns the size of the CHAR
column. When using a VARCHAR
column, trailing blanks are significant, and the
function returns the number of characters, including trailing blanks.
Solution
Check if the trailing blanks are significant when using the LENGTH()
SQL
function in your application.
RTRIM()
function:SELECT LENGTH(RTRIM(col1)) FROM table
LENGTH()
expressions can be controlled with the following FGLPROFILE
entry:dbi.database.dsname.ifxemul.length = {
true |
false }
For more details see IBM Informix emulation parameters in FGLPROFILE.