溫馨提示×

oracle中substr函數(shù)的用法是什么

小億
100
2023-09-15 10:30:30
欄目: 云計算

在Oracle中,SUBSTR函數(shù)用于從字符串中提取子字符串。其語法如下:

SUBSTR(string, start_position, [length])

其中,

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

  • start_position: 指定從哪個位置開始提取子字符串。位置是從1開始計數(shù)的。

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

例如,使用SUBSTR函數(shù)從字符串"Hello, World!“中提取子字符串"World”,可以使用以下語句:

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

結(jié)果將返回’World’。

另外,如果start_position為負數(shù),表示從字符串的末尾開始計數(shù)。例如,SUBSTR(‘Hello, World!’, -6, 5)將返回’World’。

0