Product Documentation

SQL Reference Guide

Previous Topic

Next Topic

SUBSTRING SQL Function (SQL-99 compatible)

Syntax

SUBSTRING (char_exp FROM start_position [ FOR length ])

Description

The scalar function SUBSTRING returns the substring of a character string corresponding to the first argument starting at start_position and length characters long.

The third argument length is optional. If the length is not specified the substring starting at start_position up to the end of the char_exp is returned.

Example

SELECT SUBSTRING( 'FairCom Corporation' FROM 1 FOR 7)

From customers ;

FAIRCOM

------

FairCom

1 record selected

Details

  • The first argument, char_exp, must be of character type.
  • The second argument, start_position, must be of type INTEGER.
  • The third argument, length, if specified, must be of type INTEGER.
  • The values for specifying position in char_exp 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 character type.
  • If any of the argument expressions evaluates to null, the result is null.

Note: SQL-99 compatible

TOCIndex