温馨提示×

oracle中substr的用法是什么

小云
106
2023-08-25 16:39:01
栏目: 云计算

在Oracle中,SUBSTR函数用于从字符串中提取子字符串。

语法:

SUBSTR(string, start_position, [length])

参数说明:

  • string:要提取子字符串的字符串。

  • start_position:指定开始提取的位置,从 1 开始计数。

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

示例:

  1. 提取字符串中的子字符串:

SELECT SUBSTR(‘Hello World’, 7) FROM dual;

结果:‘World’

  1. 提取字符串中指定长度的子字符串:

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

结果:‘World’

  1. 提取字符串中指定长度并在开始位置偏移的子字符串:

SELECT SUBSTR(‘Hello World’, 7, 3) FROM dual;

结果:‘Wor’

0