天天看点

Oracle SUBSTR函数 SUBSTR

Oracle SUBSTR函数 SUBSTR

<a target="_blank" href="http://docs.oracle.com/cd/b19306_01/server.102/b14200/img_text/substr.htm">description of the illustration substr.gif</a>

the <code>substr</code> functions return a portion of <code>char</code>, beginning at character <code>position</code>, <code>substring_length</code> characters

long. <code>substr</code> calculates lengths using characters as defined by the input character set. <code>substrb</code> uses bytes instead of characters. <code>substrc</code> uses unicode

complete characters. <code>substr2</code> uses ucs2 code points.<code>substr4</code> uses ucs4 code points.

if <code>position</code> is 0, then it is treated as 1.

if <code>position</code> is positive, then oracle database counts from the beginning of <code>char</code> to

find the first character.

if <code>position</code> is negative, then oracle counts backward from the end of <code>char</code>.

if <code>substring_length</code> is omitted, then oracle returns all characters to the end of <code>char</code>.

if <code>substring_length</code> is less than 1, then oracle returns null.

<code>char</code> can be any of the datatypes <code>char</code>, <code>varchar2</code>, <code>nchar</code>, <code>nvarchar2</code>, <code>clob</code>,

or <code>nclob</code>. both <code>position</code> and <code>substring_length</code> must

be of datatype <code>number</code>, or any datatype that can be implicitly converted to <code>number</code>, and must resolve to an integer. the return value is the same datatype as <code>char</code>.

floating-point numbers passed as arguments to <code>substr</code> are automatically converted to integers.

see also:

the following example returns several specified substrings of "abcdefg":

assume a double-byte database character set: