Skip to content

SUBSTR

  • string: This parameter represents the source string from which a substring is to be extracted.
  • position: This parameter determines the starting point of the substring extraction within the source string. The position is a one based index unlike most programming languages which are generally zero based.
  • length: The length parameter specifies the number of characters to be extracted from the source string. If this parameter is not included, or if it is greater than the number of characters remaining from the position in the source string, then all remaining characters will be extracted.
SELECT SUBSTR('Hello World', 1, 5);
'Hello'

The SUBSTR function is utilized in the SQL query to retrieve a substring starting from position 1 with a length of 5 characters from the string ‘Hello World’. The output, ‘Hello’, reflects this segment.