减去日期ORA01847

时间:2017-09-24 19:25:13

标签: oracle

我是Oracle的新手。我一直在研究如何用to_Date减去两天之间的例子。 但是,每次我使用to_date logic 运行它 SELECT (to_date((SELECT PAYMENT_DATE FROM INVOICES WHERE INVOICE_ID =3) - to_date((SELECT INVOICE_DUE_DATE FROM INVOICES WHERE INVOICE_ID= 3)))) FROM DUAL; 我最终收到此错误:ORA-01847:月中的某一天必须介于1和最后一天之间

付款日期为:15-SEP-17发票到期日为:24-JUN-17

有没有一种简单的方法来计算两列之间的天数差异? 提前致谢。

1 个答案:

答案 0 :(得分:0)

您不需要使用SELECT *, CASE WHEN selection = 'All Assets' THEN 'Other Assets' WHEN (isassetcode = 1 AND selection <> 'All Assets') THEN selection END AS Level5, COUNT(*) cnt FROM table --or sub-query GROUP BY list all columns in the select that corresponds the *, CASE WHEN selection = 'All Assets' THEN 'Other Assets' WHEN (isassetcode = 1 AND selection <> 'All Assets') THEN selection END 进行转换,而无需像to_date这样的格式。即省略'dd.mm.rrrr'条款。减去日期会产生一个数字(假设PAYMENT_DATE,INVOICE_DUE_DATE列都在to_date类型中)

date

其中v_day是一个数字。顺便说一下,以这种方式使用会更好:

SELECT (SELECT PAYMENT_DATE FROM INVOICES WHERE INVOICE_ID =3) - (SELECT INVOICE_DUE_DATE FROM INVOICES WHERE INVOICE_ID= 3) INTO v_day FROM DUAL;