MySQL SUBSTR function

SUBSTR function returns the sub string within a string.


SUBSTR(string, start_position, length)


SUBSTRING (string, start_position, length)

In MySQL both SUBSTR and SUBSTRING will work. SUBSTR is in ANSI standard.


mysql> select SUBSTR(‘’,1,11);
will return  –  sqlandplsql

mysql> select SUBSTRING(‘’,1,11);
will return  –  sqlandplsql

mysql> select SUBSTR(‘’,2);
will return  –  qlandplsql
If you omit the length it will default to full string length.

mysql> select SUBSTR(‘’,-3);
will return  –  com

Some more examples

select substr(‘’,1,null); —> null
select substr(‘’,null,null); —> null
select substr(‘’,0,0); —>
select substr(‘’,1,-2); —>
select substr(‘’,0,3); —>