The LENGTH() function in SQL

The semantics of the LENGTH() SQL function differs according to the database engine.

The SQL LENGTH() function must be used with care: Each database server has different semantics for this function, regarding length and trailing blanks handling.
Note: The language provides a LENGTH built-in function which is part of the runtime system. Do not confuse this with the SQL LENGTH() function, used in SQL statements. The LENGTH() function of the language returns zero when the string expression is NULL.
Table 1. SQL LENGTH() support by database brand
Database Server Type Function name Counting unit Significant trailing blanks for CHAR() columns Return value when NULL Related topic
IBM® DB2® LUW
LENGTH(expr)
Octets Yes NULL See details
IBM Informix®
LENGTH(expr)
Octets No NULL Native SQL feature
IBM Netezza
LENGTH(expr)
Characters No NULL See details
Microsoft™ SQL Server
LEN(expr)
Characters No NULL See details
Oracle® MySQL / MariadDB
LENGTH(expr)
Characters No NULL See details
Oracle Database Server
LENGTH(expr)
Characters Yes NULL See details
PostgreSQL
LENGTH(expr)
Characters No NULL See details
SAP® ASE
LEN(expr)
Characters No NULL See details
SAP HANA®
LENGTH(expr)
Characters No NULL See details
SQLite
LENGTH(expr)
Characters Yes NULL See details

Search for LENGTH() usage in your SQL statements and review the code of the database-specific function.