【问题标题】:NUMTODSINTERVAL function changes from Oracle 10g to Oracle 12cNUMTODSINTERVAL 函数从 Oracle 10g 更改为 Oracle 12c
【发布时间】:2021-06-16 13:48:38
【问题描述】:

我们的 Oracle 数据库最近从 10g 升级到 12c,导致报告发生了很多变化。以下逻辑用于以16:25:10 格式返回数据:

to_char( numtodsinterval(
 (select max(date_entered)
  from co_hist
                where order_no = a.order_no
                and   message_text = 'Delivered')
 -
 (select max(date_entered)
  from co_hist
                where order_no = a.order_no
                and   instr(message_text,'Picklist') != 0
                and   instr(message_text,'picked') != 0), 'DAY') ) elapsed_picked_delivered

升级后,同一段逻辑返回的数据为:+000000000 16:25:10.000000000

我只需要16:25:10。有没有比使用 substr() 函数去除前导/尾随 0 更简单的方法?

【问题讨论】:

  • 您也可以提及时间格式。喜欢TO_CHAR(<your_query>, 'HH:MI:SS');
  • @AnkitBajpai - 这对间隔不起作用 - 它只是被忽略了,不是吗?
  • 我不记得它在 10g 中看起来有什么不同,但无论如何,有一些想法 here 关于如何获得你想要的格式,作为一个字符串。你也可以cast(numtodsinterval(...) as interval day(0) to second(0) 但这仍然给你一个数字的天数——这当然很有用;如果没有,你可以取消它。

标签: sql oracle date


【解决方案1】:

我只需要 16:25:10。有没有比使用更简单的方法 substr() 函数去除前导/尾随 0?

解决方案之一:

regexp_substr(to_char(numtodsinterval (...your code...,'DAY')),'\d{2}:\d{2}:\d{2}')

注意 不适用于区间类型

TO_CHAR(<your_query>, 'HH:MI:SS')

【讨论】:

  • >>如果你想让“秒”可选不,这是错字...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多