Substring ([s,e])

The [] (square braces) extract a substring.

Syntax

char-variable [ start  [, end  ] ]
  1. char-variable must be a character data type variable.
  2. start defines the position of the first character of the substring to be extracted.
  3. end defines the position of the last character of the substring to be extracted.
  4. If end is not specified, only one character is extracted.

Usage

The [] (square braces) notation following a CHAR or VARCHAR variable extracts a substring from that character variable.

The start and end arguments can be expressed in bytes or characters, depending on the length semantics used in your programs.

Important: Substring expressions in SQL statements are evaluated by the database server. This may have a different behavior than the substring operator of the language.

Example

MAIN
  DEFINE s CHAR(10)
  LET s = "abcdef"
  DISPLAY s[3,4]
END MAIN