欢迎光临
我们一直在努力

oracle中substr函数用法

substr() 函数提取字符串子串,语法为:substr(str, start, [length])。用法举例:从 ‘hello world’ 中提取第 3 个字符开始的 4 个字符:select substr(‘hello world’, 3, 4) from dual; 结果:’llo’。

oracle中substr函数用法

Oracle 中 substr() 函数用法

substr() 函数用于从字符串中提取子串。其语法如下:

<code>substr(str, start, [length])</code>

其中:

  • str:要从中提取子串的字符串。
  • start:提取子串的起始位置,从 1 开始计数。
  • length(可选):要提取的子串的长度。如果省略,则提取从起始位置到字符串末尾的所有内容。

用法举例

<code>SELECT substr('Hello World', 3, 4) FROM dual;</code>

输出:

<code>llo </code>

示例说明:

  • 该查询从字符串 ‘Hello World’ 中提取了从第 3 个字符(’l’)开始的 4 个字符的子串。
  • 结果子串为 “llo”。

其他用法示例:

  • 提取字符串的第一个字符:

    <code>SELECT substr('Oracle', 1, 1) FROM dual;</code>
  • 提取字符串的最后几个字符:

    <code>SELECT substr('Database', -3) FROM dual;</code>
  • 提取指定长度的子串:

    <code>SELECT substr('Programming', 1, 8) FROM dual;</code>

注意事项:

  • start 参数必须大于或等于 1。
  • length 参数必须大于或等于 0。
  • 如果 start + length > 字符串长度,则将只提取从 start 到字符串末尾的字符。
  • 如果 start 或 length 为负数,则将返回 NULL。
赞(0) 打赏
未经允许不得转载:码农资源网 » oracle中substr函数用法
分享到

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册