这是我尝试使用的查询:
select a.cr_mdt_abstractor_dt, b.created,
(trunc(a.CR_MDT_ABSTRACTOR_DT - b.created) || ' days and ' ||<br>
to_char(to_date('01/01/2000', 'MM-DD-YYYY') + (a.CR_MDT_ABSTRACTOR_DT - b.created),
'HH24:MI:SS'
)
) as Diff
from CR_MDT a,
CR_MDT_VERIFY b
where a.CR_MDT_ID=b.FK_CR_MDT_ID
我得到的错误是:
ORA-00932:不一致的数据类型:预期NUMBER到第二天的间隔时间
b.created列的日期格式为09-MAR-17 10.52.23.195311 AM(TIMESTAMP)
和..cr_mdt_abstractor_dt的列在DATE。
我是否可以获得帮助以更正查询,以便将列b.created转换为格式以从a.cr_mdt_abstractor_dt中提取?
答案 0 :(得分:1)
分别在TRUNC
(CR_MDT_ABSTRACTOR_DT
)和TIMESTAMP
上使用created
。
SELECT a.cr_mdt_abstractor_dt,
b.created,
TRUNC(a.CR_MDT_ABSTRACTOR_DT) - TRUNC(b.created)
|| ' days and '
|| TO_CHAR(to_date('01/01/2000', 'MM-DD-YYYY') + (a.CR_MDT_ABSTRACTOR_DT - b.created), 'HH24:MI:SS' ) AS Diff
FROM CR_MDT a,
CR_MDT_VERIFY b
WHERE a.CR_MDT_ID=b.FK_CR_MDT_ID;
示例输出:
CREATED DIFF
07-09-17 -182 days and 12:15:15