Substr

From Oracle FAQ
(Redirected from SUBSTR)
Jump to: navigation, search

SUBSTR is an SQL function that returns a portion of a string (char or varchar2) value.

[edit] Syntax

SUBSTR(string, start_pos, length)

If "start_pos" is negative, substr counts from the end of the string. If "length" is not given, substr defaults to the remaining length of the string.

[edit] Examples

SELECT SUBSTR('123', 1, 1) FROM dual;
S
-
1
SQL> SELECT SUBSTR('123', 1, 2) FROM dual;
SU
--
12
SQL> SELECT SUBSTR('123', 2, 1) FROM dual;
S
-
2
SQL> SELECT SUBSTR('123', 2, 2) FROM dual;
SU
--
23

[edit] Also see