Returns a substring of a source string, based on starting position and substring length.


SUBSTR( expression, startingPosition [, stringLength ] )


  • expression: a character expression.
  • startingPosition: an integer of the starting position for the substring. The first character in the string is position 1.
  • stringLength: an optional string length.
    • If this value is omitted the substring will contain all characters to the end of the string.
    • This value cannot be larger than the number of characters from startingPosition to the end of the string.


  • A VARCHAR value.


SELECT firstName, SUBSTR(firstName) AS firstNameSubstr FROM MYSQL.inventory.cust;

VALUES SUBSTR('John Smith', 3, 4);
-- Returns hn S

VALUES SUBSTR('John Smith', 3);
-- Returns hn Smith