温馨提示×

oracle中substr函数的用法是什么

小亿
99
2023-09-15 10:30:30
栏目: 云计算

在Oracle中,SUBSTR函数用于从字符串中提取子字符串。其语法如下:

SUBSTR(string, start_position, [length])

其中,

  • string: 指定要提取子字符串的原始字符串。

  • start_position: 指定从哪个位置开始提取子字符串。位置是从1开始计数的。

  • length(可选): 指定要提取的子字符串的长度。如果省略该参数,则提取从start_position开始到字符串末尾的所有字符。

例如,使用SUBSTR函数从字符串"Hello, World!“中提取子字符串"World”,可以使用以下语句:

SELECT SUBSTR(‘Hello, World!’, 8, 5) FROM dual;

结果将返回’World’。

另外,如果start_position为负数,表示从字符串的末尾开始计数。例如,SUBSTR(‘Hello, World!’, -6, 5)将返回’World’。

0