我有一个表格,recorded
列定义为timestamp
,如下所示:
TIMESTAMP(6) RECORDED
我想选择所有记录过的记录"两个时间戳之间。为此,我写了以下查询:
SELECT * FROM myTable WHERE
recorded BETWEEN 1414794711050 AND 1415399511053;
执行此操作时,我收到错误
ORA-00932:数据类型不一致:预期TIMESTAMP,NUMBER得到 00932. 00000 - "数据类型不一致:预期%s获得%s"
我也尝试过:
SELECT * FROM myTable WHERE
recorded BETWEEN to_timestamp(1414794711) AND to_timestamp(1415399511);
如何使此查询正常工作?
答案 0 :(得分:3)
SELECT * FROM myTable
WHERE recorded BETWEEN to_date('19700101', 'YYYYMMDD') + 1414794711050/24/60/60/1000
and to_date('19700101', 'YYYYMMDD') + 1415399511053/24/60/60/1000;
1414794711050/24/60/60/1000
将毫秒转换为若干天(一天24小时,一小时60小时,一分钟60秒)
to_date('19700101', 'YYYYMMDD')
+ [N天] =新日期(N天后)