Explain SUBSTRING() Function in SQL?

The SUBSTRING() function extracts a substring starting from a position in an input string with a given length. In the case of a substring, you need an input string and need to mention the starting point and the total length of the string.

Input: String, start, length 
Output: substring.

Syntax :

SUBSTRING(input_string, start, length);

Parameter :

SUBSTRING function accepts three-parameter like String, start, length. Let’s have a look.

  • input_string –It can be a character, binary, text, ntext, or image expression.
  • start – It is an integer defining the location where the returned substring starts. The first position in the string is 1.
  • length – It is a positive integer that specifies the number of characters to be returned from the substring.

Returns :

It returns a substring with a specified length starting from a location in an input string.


Using SUBSTRING() function with literal strings.

SELECT SUBSTRING('Hello World', 7, 5 ) 
AS ExtractString;

Output :