【问题标题】:how to extract last day date of the month from this string 'opimus_rise_issue_command_201912.txt'如何从此字符串'opimus_rise_issue_command_201912.txt'中提取该月的最后一天日期
【发布时间】:2019-10-23 12:41:00
【问题描述】:

我想要字符串中相应月份和年份的最后日期

'opimus_rise_issue_command_201912.txt'

预期输出--

20191231

【问题讨论】:

    标签: sql oracle


    【解决方案1】:

    一些嵌套函数可能会有所帮助。

    SQL> with test (col) as
      2    (select 'opimus_rise_issue_command_201912.txt' from dual)
      3  select to_char(last_day(to_date(regexp_substr(col, '\d+'), 'yyyymm')), 'yyyymmdd') result
      4  from test
      5  /
    
    RESULT
    --------------------------------------------------
    20191231
    
    SQL>
    

    【讨论】:

    • 最终结果是字符串或日期数据类型。我需要日期数据类型最终结果
    • 这是一个字符串,格式如您的示例所示。只需删除最外层的 TO_CHAR,它就是一个 DATE。
    【解决方案2】:

    检查一下

     select LAST_DAY(to_date(regexp_replace('opimus_rise_issue_command_201912.txt', '[^0-9]', '') ||'01','yyyymmdd')) from dual;
    

    2019 年 12 月 31 日

    【讨论】:

      猜你喜欢
      • 2012-11-17
      • 1970-01-01
      • 2022-01-21
      • 2013-03-04
      • 1970-01-01
      • 1970-01-01
      • 2019-12-22
      • 2010-12-13
      • 1970-01-01
      相关资源
      最近更新 更多