PL/SQL 提取不同格式日期之间的差异
PL/SQL Extracting difference between dates in different formats
这是我正在尝试使用的查询:
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: inconsistent datatypes: expected NUMBER got INTERVAL DAY TO SECOND
b.created 列采用日期格式 09-MAR-17 10.52.23.195311 AM(TIMESTAMP)
a.cr_mdt_abstractor_dt 的列在日期中。
我能否获得帮助来更正查询,使列 b.created 转换为从 a.cr_mdt_abstractor_dt 中提取的格式?
分别在 CR_MDT_ABSTRACTOR_DT
(TIMESTAMP
) 和 created
上使用 TRUNC
。
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
这是我正在尝试使用的查询:
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: inconsistent datatypes: expected NUMBER got INTERVAL DAY TO SECOND
b.created 列采用日期格式 09-MAR-17 10.52.23.195311 AM(TIMESTAMP)
a.cr_mdt_abstractor_dt 的列在日期中。
我能否获得帮助来更正查询,使列 b.created 转换为从 a.cr_mdt_abstractor_dt 中提取的格式?
分别在 CR_MDT_ABSTRACTOR_DT
(TIMESTAMP
) 和 created
上使用 TRUNC
。
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