SUBSTRING Function - Sybase ASE to MariaDB Migration

In Sybase ASE, the SUBSTRING function returns a substring from a string, starting at the specified position and for the specified length. SUBSTRING always takes three arguments.

In MariaDB, you can also use the SUBSTRING function.

Sybase ASE:

  -- Get first 3 characters
  SELECT SUBSTRING('New York', 1, 3);
  /* New */

MariaDB:

  -- Get first 3 characters
  SELECT SUBSTRING('New York', 1, 3);
  /* New */

Positive Start Position

Sybase ASE SUBSTRING requires a positive start position, otherwise it returns NULL.

Sybase ASE:

  -- Zero start position
  SELECT SUBSTRING('New York', 0, 3);
  /* NULL */
 
  -- Negative start position
  SELECT SUBSTRING('New York', -1, 3);
  /* NULL */

MariaDB returns an empty string ('') when the start position is 0. When a negative start position is used, it counts backward from the end of the string.

MariaDB:

  -- Zero start position
  SELECT SUBSTRING('New York', 0, 3);
  /* '' */
 
  -- Negative start position
  SELECT SUBSTRING('New York', -1, 3);
  /* k */

For more information, see Sybase ASE to MariaDB Migration.