login

SQL SUBSTRING

In order to get a part of a string we can use SQL SUBSTRING function. There are two variants of SQL SUBSTRING function as follow:

	SUBSTRING(str,pos)
	SUBSTRING(str,pos,len)

The first function returns a substring from the base string str starting at position pos. The second function returns a substring from the base string str starting at position pos and continuing characters in length len, consider bellow examples:

	SELECT SUBSTRING('substring function',10) 
	AS SUB_STRING

And here is the output

SUB_STRING
----------
 function 
	SELECT SUBSTRING('substring function',10,5) 
	AS SUB_STRING
SUB_STRING
----------
 func   

SQL SQL SUBSTRING function is available in almost SQL database server such as Microsoft SQL server, MySQL, Sybase ASE and in Oracle it is implemented as SUBSTR function.

Read On