The SUBSTR() function returns part of the given string based on the given starting point to a certain length in MySQL.
syntax :
SUBSTR(string, start,length)
the first argument is string field or string value
start is the starting point of the string from where
length defines how many characters need to return or extract, length is optional
the function SUBSTR returns part of the string.
how does the SUBSTR function work in MySQL?
let us get by example how the SUBSTR function works?
select SUBSTR("MYSQL", 3,3) so SUBSTR function return "SQL" from "MYSQL" because it had second argument 3 which is say SUBSTR method to start to return part of after of 3 characters of the given string.
examples :
select SUBSTR("MYSQL", 3)
// return is SQL
select SUBSTR("MYSQL", -4)
// return is YSQL
select SUBSTR("MYSQL", 0)
// return is NULL OR EMPTY
if you give second argument more than main string length than it returns null or empty by SUBSTR() function in MySQL.
select SUBSTR("MYSQL",10)
// return is NULL OR EMPTY
if you don't provide the last argument length then it takes as main string full length.
select SUBSTR("MYSQL",1,2);// return is MY
select SUBSTR("MYSQL",1);// return is MYSQL