【问题标题】:How do I extract a substring starting from end of string until the second 0 is encountered, oracle?如何从字符串末尾开始提取子字符串,直到遇到第二个 0,oracle?
【发布时间】:2015-12-14 00:12:49
【问题描述】:

我有一个表client_requests 与列number_request。 在number_request栏目中我有如下记录:

20130000000008,
20130000000010,
20130000000503

我想只提取没有0的字符串结尾,

示例:

for 20130000000008 I want to get 8
for 20130000000010 I want to get 10
for 20130000000503 I want to get 503

我想我需要使用regexp_substr,但不知道如何使用。

【问题讨论】:

  • 需要定义起始位置,因为20130000000503的结果可能是3、503或130000000503。
  • 谢谢,我找到了解决方案。我得到 max(number_request) 然后我使用 to_number 作为从数字 0 的第一个位置(在字符串中)开始到结束的子字符串。在我的情况下,max(number_request) 是 20150000001118,那么我的解决方案是 to_number(substr(number_requests,11,14)。非常感谢。

标签: sql oracle substring


【解决方案1】:

一种可能的解决方案:

select replace('201500000010',regexp_substr('201500000010','.{4}0*'),'') from dual;

本质上,我是使用 regexp_subst 函数来提取不需要的数字,然后使用 replace 函数将不需要的数字替换为 '',这没什么。

【讨论】:

    猜你喜欢
    • 2014-01-04
    • 2011-02-05
    • 1970-01-01
    • 2018-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-01
    相关资源
    最近更新 更多