获取错误:SQL中的ORA-01858

时间:2015-10-07 09:05:15

标签: sql oracle

我收到了错误

  

ORA-01858:找到数字所在的非数字字符   预期

select pia.vendor_id,
       pia.invoice_id,
       pia.invoice_date,
       pia.invoice_amount amount
from ap_invoices_all pia
where 1=1
  and (pia.invoice_date < to_date(&p_from_date, 'DD-MM-YYYY') or &p_from_date is not null )

invoice_date是DATE。

但如果替换为:

pia.invoice_date < to_date('18/01/2015', 'dd/MM/yyyy')

是对的。

为什么不正确?以及如何解决?

1 个答案:

答案 0 :(得分:0)

这是因为你错过了替换变量周围的引号。试试这个:

select pia.vendor_id,
       pia.invoice_id,
       pia.invoice_date,
       pia.invoice_amount amount
from ap_invoices_all pia
where 1=1
  and (pia.invoice_date < to_date('&p_from_date', 'DD-MM-YYYY') or '&p_from_date' is not null);