删除PL/SQL中特定字符之后的所有字符 [英] Remove all characters after a specific character in PL/SQL

查看:143
本文介绍了删除PL/SQL中特定字符之后的所有字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I get a substring from this example value:

 john.abc_1234

我希望它返回john.abc.因此基本上,我们需要删除_之后的所有信息.

I want it to return john.abc.So basically we need to remove all the information after _.

更多示例:1234_abc

More examples: 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路径,该路径可以更有效地处理异常.

Additionally, if you are running from Oracle 10g on, you could take the Regex path, which would more powerfully handle exceptions.

以下是有关如何在Oracle中进行操作的链接:

Here are some links on how to do it in 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

这篇关于删除PL/SQL中特定字符之后的所有字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆