LEN Function - Sybase ASE to MariaDB Migration

In Sybase ASE you can use the LEN function to get the number of characters in the string.

Note that LEN includes the trailing spaces (although the Sybase ASE SQL reference states otherwise), and returns 1 as the length of empty string. '' This also applies to Sybase ASE CHAR_LENGTH function.

Sybase ASE:

SELECT LEN('a');
-- Result: 1
 
SELECT LEN('a ');
-- Result: 2
 
/* Note that the length of empty string is 1 */
SELECT LEN('');
-- Result: 1
 
SELECT LEN(NULL);
-- Result: NULL

In MariaDB you can use CHAR_LENGTH function to get the number of characters in string. It includes the trailing spaces and unlike Sybase ASE returns 0 as the length of empty string.

MariaDB:

SELECT CHAR_LENGTH('a');
-- Result: 1
 
SELECT CHAR_LENGTH('a ');
-- Result: 2
 
SELECT CHAR_LENGTH('');
-- Result: 0
 
SELECT CHAR_LENGTH(NULL);
-- Result: NULL

For more information, see Sybase ASE to MariaDB Migration.