ROW_ID STATUS CREATED_DATE
123 PROCESSED 06/01/16 03:17:59 AM - 1-XHV8EV
123 INPROGRESS 06/01/16 03:18:59 AM - 1-XHV8EV
123 INPROGRESS 06/02/16 10:17:59 AM - 1-XHV8EV
123 INPROGRESS 06/02/16 10:18:59 AM - 1-XHV8EV
123 PROCESSED 06/02/16 11:17:59 AM - 1-XHV8EV
123 PROCESSED 06/02/16 11:17:59 AM - 1-XHV8EV
我想检索日期为06/01/16 03:1:59 AM至06/02/16 11:17:59 AM之间的所有记录
输出应该是这样的
输出:
ROW_ID STATUS CREATED_DATE
123 INPROGRESS 06/01/16 03:18:59 AM - 1-XHV8EV
123 INPROGRESS 06/02/16 10:17:59 AM - 1-XHV8EV
123 INPROGRESS 06/02/16 10:18:59 AM - 1-XHV8EV
我想检索日期为06/01/16 03:1:59 AM至123 PROCESSED 06/02/16 11:17:59 AM之间的所有记录
答案 0 :(得分:1)
Oracle安装程序:
CREATE TABLE table_name ( ROW_ID, STATUS, CREATED_DATE ) AS
SELECT 123, 'PROCESSED', '06/01/16 03:17:59 AM - 1-XHV8EV' FROM DUAL UNION ALL
SELECT 123, 'INPROGRESS', '06/01/16 03:18:59 AM - 1-XHV8EV' FROM DUAL UNION ALL
SELECT 123, 'INPROGRESS', '06/02/16 10:17:59 AM - 1-XHV8EV' FROM DUAL UNION ALL
SELECT 123, 'INPROGRESS', '06/02/16 10:18:59 AM - 1-XHV8EV' FROM DUAL UNION ALL
SELECT 123, 'PROCESSED', '06/02/16 11:17:59 AM - 1-XHV8EV' FROM DUAL UNION ALL
SELECT 123, 'PROCESSED', '06/02/16 11:17:59 AM - 1-XHV8EV' FROM DUAL;
<强>查询强>:
SELECT *
FROM table_name
WHERE TO_DATE( SUBSTR( created_date, 1, 20 ), 'MM/DD/YY HH12:MI:SS AM' )
BETWEEN TIMESTAMP '2016-06-01 03:18:59'
AND TIMESTAMP '2016-06-02 11:17:00';
<强>输出强>:
ROW_ID STATUS CREATED_DATE
---------- ---------- -------------------------------
123 INPROGRESS 06/01/16 03:18:59 AM - 1-XHV8EV
123 INPROGRESS 06/02/16 10:17:59 AM - 1-XHV8EV
123 INPROGRESS 06/02/16 10:18:59 AM - 1-XHV8EV
答案 1 :(得分:0)
那是&#34; - 1-XHV8EV&#34;部分数据?如果是这样,你将不得不做一些花哨的SQL语句来消除它。
这就像是
CAST (LEFT(CREATED_DATE,20) as DATE)
哪个应该给你一个CASTed日期。然后你可以在中间运行
WHERE CAST (LEFT(CREATED_DATE,20) as DATE) between someDate and someOtherDate
答案 2 :(得分:0)
所有说和做,这些修复都是暂时的。此问题的永久性修复仅适用于表格设计。如果这是一项重大工作,请尝试设计一个计划,将其分解为多个较小的任务,逐步更改逻辑依赖的对象,最终一劳永逸地解决这个问题。
祝你好运。