gpt4 book ai didi

sql - PLSQL 从字符串末尾开始显示数字

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

我有以下问题。有一个字符串:

有东西 2015.06.06。在空中 1234567 242424 2015.06.07. 12125235

我只需要显示此字符串的最后一个日期:2015.06.07。我尝试使用 regexp_substrinsrt 但它不起作用。所以这只是测试,如果我可以用这个解决方案解决这个问题,我应该将它用于有多个日期的 CLOB 查询,我只需要最后一个。我知道有regexp_count,它有助于解决这个问题,但我使用的数据库是Oracle 10g,所以它不会工作。

有人可以帮帮我吗?

最佳答案

找到这个问题的解决方案的关键是反转 this answer 中出现的字符串中的单词的想法。

这是可能的解决方案:

WITH words AS
(
SELECT regexp_substr(str, '[^[:space:]]+', 1, LEVEL) word,
rownum rn
FROM (SELECT 'There is something 2015.06.06. in the air 1234567 242424 2015.06.07. 2015.06.08 2015.06.17. 2015.07.01. 12345678999 12125235' str
FROM dual) tab
CONNECT BY LEVEL <= LENGTH(str) - LENGTH(REPLACE(str, ' ')) + 1
)
, words_reversed AS
(
SELECT *
FROM words
ORDER BY rn DESC
)
SELECT regexp_substr(word, '\d{4}\.\d{2}\.\d{2}', 1, 1)
FROM words_reversed
WHERE regexp_like(word, '\d{4}\.\d{2}\.\d{2}')
AND rownum = 1;

关于sql - PLSQL 从字符串末尾开始显示数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31099225/

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