APPX Software Library

Chapter 4: SQL Language Elements

4.9.2.79 SUBSTRING function (ODBC compatible)

Syntax

SUBSTRING ( char_expression, start_position [, length ] )

Description

The scalar function SUBSTRING returns the substring of the character string corresponding to the first argument starting at start_position and length characters long. If the third argument length is not specified, the substring starting at start_position up to the end of char_expression is returned. SUBSTRING is identical to SUBSTR but provides ODBC-compatible syntax.

Example

SELECT name, '(', SUBSTRING (phone, 1, 3) , ')',
               SUBSTRING (phone, 4, 3), '-',
               SUBSTRING (phone, 7, 4)
     FROM customer ;

Notes

  • The first argument must be of type CHARACTER.
  • The second argument must be of type INTEGER.
  • The third argument, if specified, must be of type INTEGER.
  • The values for specifying position in the character string start from 1: The very first character in a string is at position 1, the second character is at position 2 and so on.
  • The result is of type CHARACTER.
  • If any of the argument expressions evaluates to null, the result is null.