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 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 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 CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, 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
相关文章
|
SQL Oracle 算法
|
SQL Oracle 关系型数据库
JAVAEE框架数据库技术之12_oracle常用函数和高级查询子查询
JAVAEE框架数据库技术之12_oracle常用函数和高级查询子查询
421 0
JAVAEE框架数据库技术之12_oracle常用函数和高级查询子查询
|
存储 Java 数据库
JAVAEE框架数据库技术之13_oracle 之PLSQL技术及存储过程和函数(二)
JAVAEE框架数据库技术之13_oracle 之PLSQL技术及存储过程和函数
388 0
|
SQL 存储 Oracle
【YashanDB知识库】Oracle pipelined函数在YashanDB中的改写
【YashanDB知识库】Oracle pipelined函数在YashanDB中的改写
|
SQL Oracle 关系型数据库
Oracle|内置函数之INSTR
【7月更文挑战第5天】
|
SQL Oracle 关系型数据库
|
Oracle 关系型数据库 数据挖掘
|
NoSQL Oracle 关系型数据库
MongoDB与Oracle:管道函数兼容之道
【4月更文挑战第20天】
425 2
|
Oracle 关系型数据库 数据管理
Oracle常用系统函数之日期和时间类函数:时空穿梭者的魔法棒
【4月更文挑战第19天】Oracle数据库中的日期和时间函数是强大的工具,如同时空穿梭者的魔法棒。`SYSDATE`和`CURRENT_TIMESTAMP`能显示当前时间,助你在数据中记录关键时刻;`ADD_MONTHS`函数让你轻易跃过月份,实现时间穿越;而`TO_DATE`和`TO_CHAR`则负责日期和时间的格式转换,如同时间的化妆师。除此之外,还有`EXTRACT`、`LAST_DAY`等更多魔法道具,帮助数据管理专家们自如操控时间,解决各种挑战。掌握这些函数,你也能在数据世界中自由穿梭!
|
Oracle 算法 关系型数据库
Oracle常用系统函数之数字类函数:数字的魔术师
【4月更文挑战第19天】Oracle数据库中的数字类函数是数字处理的魔术师,包括`ROUND`(四舍五入),`CEIL`和`FLOOR`(向上/下取整),以及`ABS`(计算绝对值)。还有`MOD`、`TRUNC`和`POWER`等函数,提供求余数、截断和计算幂的功能。熟练运用这些函数能提升数据管理效率,让处理数字变得更简单、有趣。

推荐镜像

更多