gpt4 book ai didi

sql - 删除 PL/SQL 中特定字符后的所有字符

转载 作者:行者123 更新时间:2023-12-02 11:25:32 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





How to remove part of the string in oracle

(3 个回答)


1年前关闭。




如何从此示例值中获取子字符串:

 john.abc_1234

我要它返回 john.abc .所以基本上我们需要删除 _之后的所有信息.

更多示例:1234_abc

最佳答案

您可以使用 SUBSTRINSTR :

select substr('john.abc_1234', 1, instr('john.abc_1234', '_') -1)
from dual

Warning: This is only guaranteed to work if your string actually has an underscore in it



更新

此外,如果您从 Oracle 10g 开始运行,您可以采用 Regex 路径,它可以更强大地处理异常。

以下是有关如何在 Oracle 中执行此操作的一些链接:
  • http://psoug.org/reference/regexp.html
  • http://psoug.org/snippet/Regular-Expressions--Regexp-Cheat-Sheet_856.htm
  • http://www.regular-expressions.info/oracle.html
  • 关于sql - 删除 PL/SQL 中特定字符后的所有字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7717566/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com