Purpose
The SUBSTR functions return a portion of chars, beginning at character position, substring_length characters long. SUBSTR calculates lengths using characters as defined by the input character set. SUBSTRB uses bytes instead of characters. SUBSTRC uses Unicode complete characters. SUBSTR2 uses UCS2 code points. SUBSTR4 uses UCS4 code points.
If position is 0, then it is treated as 1.
If position is positive, then Oracle Database counts from the beginning of-
If position is negative, then Oracle counts backward to the end of Char.
If Substring_length is omitted, then Oracle returns all characters to the "end of". If Substring_length is less than 1, then Oracle returns NULL.
Char can is any of the datatypes char, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. Both position and Substring_length must being datatype number, or any datatype so can is implicitly converted to number, and must resolve to an integer. The return value was the same datatype as char. Floating-point numbers passed as arguments to SUBSTR are automatically erted to integers.
Also:oracle Database Globalization Support Guide For more information about SUBSTR functions and length semantics in Different locales
Examples
The following example returns several specified substrings of "ABCDEFG":
Select SUBSTR (' ABCDEFG ', 3,4) "Substring" from
DUAL;
Substring
---------
cdef
SELECT SUBSTR (' ABCDEFG ', -5,4) "Substring" from
DUAL;
Substring
---------
cdef
Assume a double-byte database character set:
select substrb (' ABCDEFG ', 5,4.2) "Substring with bytes" from DUAL; Substring with bytes--------------------CD