Oracle SUBSTR函数

简介: SUBSTR Syntax substr::= Description of the illustration substr.gif Purpose The SUBSTR functions return a portion of char, beginning at character position, substring_length characte

SUBSTR

Syntax

substr::=

Description of substr.gif follows
Description of the illustration substr.gif

Purpose

The SUBSTR functions return a portion of char, beginning at character positionsubstring_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 char to find the first character.

  • If position is negative, then Oracle counts backward from the end of char.

  • If substring_length is omitted, then Oracle returns all characters to the end of char. If substring_length is less than 1, then Oracle returns null.

char can be any of the datatypes CHARVARCHAR2NCHARNVARCHAR2CLOB, or NCLOB. Both position and substring_length must be of datatype NUMBER, or any datatype that can be implicitly converted to NUMBER, and must resolve to an integer. The return value is the same datatype as char. Floating-point numbers passed as arguments to SUBSTR are automatically converted to integers.

See 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
目录
相关文章
|
6月前
|
SQL Oracle 关系型数据库
Oracle之regexp系列函数详解
Oracle之regexp系列函数详解
550 1
|
4月前
|
SQL Oracle 关系型数据库
Oracle|内置函数之INSTR
【7月更文挑战第5天】
|
11月前
|
Oracle 关系型数据库
oracle 函数 regexp_substr()
oracle函数regexp_substr,测试使用
200 0
|
移动开发 Oracle 关系型数据库
Oracle to_char 函数
Oracle to_char 函数
932 0
|
SQL Oracle 关系型数据库
Oracle字符串连接的方法
和其他数据库系统类似,Oracle字符串连接使用“||”进行字符串拼接,其使用方式和MSSQLServer中的加号“+”一样。
3010 0
|
Oracle 关系型数据库
关于Oracle REGEXP_COUNT函数用法总结
关于Oracle REGEXP_COUNT函数用法总结
2506 0
|
Oracle 关系型数据库
|
Oracle 关系型数据库 索引
|
Oracle 关系型数据库 机器学习/深度学习
|
关系型数据库 Oracle
instr函数的使用-oracle
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010741376/article/details/51149506 instr(string1,string2[,start_position[,nth_appearence]]) string1:要在此字符串中查找。
777 0