Tuesday, 14 October 2014

MySQL: Substring

The SUBSTRING function returns a substring from a string starting at a specific position with a given length. MySQL provides various forms of the substring function.

Syntax:   SUBSTR(string,position,length)
Another syntax: SUBSTR(string,FROM position,FOR length)

Arguments:
string: A string
position: Starting position
length: Length in characters and it is optional.

MySQL substring - string demo
-15 -14 -13 -12 -11 -10 -9  -8   -7   -6   -5  -4   -3   -2   -1

SUBSTRING('MySQL SUBSTRING',5,6)   // L SUBS

SUBSTRING('MySQL SUBSTRING',5)      // L SUBSTRING    (FROM postion 5 to end)

SUBSTRING('MySQL SUBSTRING',-5)      // TRING

SUBSTRING('MySQL SUBSTRING',-10,6)   //    L SUBS

SUBSTRING('MySQL SUBSTRING',FROM 5 FOR 6)  //   L SUBS



The SUBSTR() is synonym for the  SUBSTRING() so you can use both of them interchangeably.




SUBSTRING(str, pos, len)

ING() returns a specified number of characters from a particular position of a given string. - See more at: http://www.w3resource.com/mysql/string-functions/mysql-substring-function.php#sthash.IH603WfX.dpuf
MySQL SUBSTRING() returns a specified number of characters from a particular position of a given string.

Syntax

SUBSTRING(str, pos, len)
- See more at: http://www.w3resource.com/mysql/string-functions/mysql-substring-function.php#sthash.IH603WfX.dpuf
MySQL SUBSTRING() returns a specified number of characters from a particular position of a given string.

Syntax

SUBSTRING(str, pos, len)
- See more at: http://www.w3resource.com/mysql/string-functions/mysql-substring-function.php#sthash.IH603WfX.dpuf
MySQL SUBSTRING() returns a specified number of characters from a particular position of a given string.

Syntax

SUBSTRING(str, pos, len)
- See more at: http://www.w3resource.com/mysql/string-functions/mysql-substring-function.php#sthash.IH603WfX.dpuf
MySQL SUBSTRING() returns a specified number of characters from a particular position of a given string.

Syntax

SUBSTRING(str, pos, len)
- See more at: http://www.w3resource.com/mysql/string-functions/mysql-substring-function.php#sthash.IH603WfX.dpuf

0 comments:

Post a Comment