Oracle® OLAP DML Reference 10g Release 1 (10.1) Part Number B10339-02 |
|
|
View PDF |
The SUBSTR function returns a portion of string, beginning at a specified character position, and a specified number of characters long. SUBSTR calculates lengths using characters as defined by the input character set.
To retrieve a portion of string based on bytes, use SUBSTRB.
Return Value
The return value is the same data type as string.
Syntax
SUBSTR (string , position [, substring_length])
Arguments
A text expression that is the base string from which the substring is created.
The position at which the first character of the returned string begins.
When position is 0
(zero), then it is treated as 1
.
When position is positive, then the function counts from the beginning of string to find the first character.
When position is negative, then the function counts backward from the end of string.
The number of characters in the returned string. When you do not specify a value for this argument, then the function returns all characters to the end of string. When you specify a value that is less than 1
, the function returns NA
.
Examples
The following example returns several specified substrings of "abcdefg".
SHOW SUBSTR('abcdefg',3,4) cdef SHOW SUBSTR('abcdefg',-5,4) cdef