这个问题在这里已经有了答案:
How to remove part of the string in oracle
(3 个回答)
1年前关闭。
如何从此示例值中获取子字符串:
john.abc_1234
我要它返回
john.abc
.所以基本上我们需要删除_
之后的所有信息.更多示例:1234_abc
最佳答案
您可以使用 SUBSTR
和 INSTR
:
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 中执行此操作的一些链接:
关于sql - 删除 PL/SQL 中特定字符后的所有字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7717566/