oracle中substr的用法是什么

小云
109
2023-08-25 16:39:01
欄目: 云計(jì)算

在Oracle中,SUBSTR函數(shù)用于從字符串中提取子字符串。

語法:

SUBSTR(string, start_position, [length])

參數(shù)說明:

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

  • start_position:指定開始提取的位置,從 1 開始計(jì)數(shù)。

  • length:可選參數(shù),指定要提取的子字符串的長(zhǎng)度。如果省略該參數(shù),則提取從 start_position 開始到字符串末尾的所有字符。

示例:

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

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

結(jié)果:‘World’

  1. 提取字符串中指定長(zhǎng)度的子字符串:

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

結(jié)果:‘World’

  1. 提取字符串中指定長(zhǎng)度并在開始位置偏移的子字符串:

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

結(jié)果:‘Wor’

0