【问题标题】:ORACLE Convert the long millisecond into DateORACLE 将长毫秒转换为日期
【发布时间】:2012-02-28 14:11:31
【问题描述】:

我在 ORACLE 中有一个字段为 CREATED (NUMBER)。它以 MILLISECONDS 存储时间,或者您可以说长格式。现在的要求是使用字段 CREATED 查找两个日期之间的数据。

我有以下查询,它适用于 where 条件,但不适用于 between 条件:

SELECT date'1970-01-01' + TIMECREATED / 1000 / 60 / 60 / 24 as timet 
FROM XXX_TABLE WHERE ITBD='829993';

有人可以提供 SQL 来获取两个日期之间的数据吗?

【问题讨论】:

  • 请您告诉我们工作的代码吗?
  • ...并解释它以什么方式无法工作?

标签: sql oracle9i


【解决方案1】:

使用 Oracle 日期文字、时间戳和每日间隔:

你可以试试这样的:

select *
  from the_table where to_timestamp(the_date_column,'DD/MM/YYYY') - date'1970-01-01'
                 between numtodsinterval(first_created/1000,'second') and numtodsinterval(second_created/1000,'second')

select *
  from the_table
 where date'1970-01-01' + numtodsinterval(created/1000,'second')
       between to_timestamp('2011-01-01','YYYY-MM-DD')
           and to_timestamp('2012-01-01','YYYY-MM-DD')

【讨论】:

    猜你喜欢
    • 2019-12-24
    • 1970-01-01
    • 2010-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-10
    • 2019-12-05
    相关资源
    最近更新 更多