Substring/Substr Function; Alternative Forms; Considerations For Substring/Substr; Requirements For The Expression, Length, And Start Position - HP Neoview SQL Reference Manual

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

SUBSTRING/SUBSTR Function

The SUBSTRING function extracts a substring out of a given character expression. It returns a
character string of data type VARCHAR, with maximum length equal to the fixed length or
maximum variable length of the character expression. SUBSTR is equivalent to SUBSTRING.
SUBSTRING (character-expr FROM start-position [FOR length])
or:
SUBSTRING (character-expr,start-position,length)
character-expr
specifies the source string from which to extract the substring. The source string is an SQL
character value expression. The operand is the result of evaluating character-expr. See
"Character Value Expressions" (page
start-position
specifies the starting position start-position within character-expr at which to start
extracting the substring. start-position must be a value with an exact numeric data type
and a scale of zero.
length
specifies the number of characters to extract from character-expr.length is the length
of the extracted substring and must be a value greater than or equal to zero of exact numeric
data type and with a scale of zero.
If you are using the FROM keyword, the length field is optional, therefore, if you do not
specify the substring length, all characters starting at start-position and continuing
until the end of the character expression are returned. If you are not using the FROM and
FOR keywords, the length field is required.

Alternative Forms

The SUBSTRING function treats SUBSTRING( string FOR int ) equivalent to SUBSTRING(
string FROM 1 FOR int ). The Neoview database software already supports the ANSI
standard form as:
SUBSTRING(string FROM int
The SUBSTRING function treats SUBSTRING (string, Fromint) equivalent to
SUBSTRING(string FROM Fromint). The Neoview database software already supports
SUBSTRING (string, Fromint, Forint) as equivalent to the ANSI standard form:
SUBSTRING(string FROM Fromint FOR Forint)

Considerations for SUBSTRING/SUBSTR

Requirements for the Expression, Length, and Start Position

The data types of the substring length and the start position must be numeric with a scale
of zero. Otherwise, an error is returned.
If the sum of the start position and the substring length is greater than the length of the
character expression, the substring from the start position to the end of the string is returned.
If the start position is greater than the length of the character expression, an empty string
('') is returned.
The resulting substring is always of type VARCHAR. If the source character string is an
upshifted CHAR or VARCHAR string, the result is an upshifted VARCHAR type.

Examples of SUBSTRING/SUBSTR

Extract 'Ro':
208).
[ FOR int ])
SUBSTRING/SUBSTR Function
411

Advertisement

Table of Contents
loading

Table of Contents