Previous Topic: Standard deviation populationNext Topic: Sum


Substring

The substring function returns the substring of a string value, starting from a specified position and continuing for a specified length.

Syntax:

►►─┬─ SUBS ──────┬─ (string, starting-position ─┬───────────┬─ ) ─────────────►◄
   ├─ SUBSTR ────┤                              └─ ,length ─┘
   └─ SUBSTRING ─┘

Invocation names:

SUBS
SUBSTR
SUBSTRING

Parameters:

string

Specifies the string value from which the substring is taken.

starting-position

Specifies the numeric starting position of the substring within the string value. Starting-position must be a positive number and not greater than the length of the string value.

length

Specifies the numeric length of the substring within the string value (optional). The sum of starting-position and length, minus one, cannot be greater than the length of the string value. If length-evn is not specified, the substring is taken from the specified starting position to the end of the string value.

Example:

This example extracts the first seven characters of each employee's last name.

select substr(emp-last-name-0415,1,7) from employee
  EMPLOYEE REPORT
     09/15/96



  LITERAT
  HEAROWI
  PAPAZEU
  HEDGEHO
  MCDOUGA