2015-10-07 47 views
-1

,我發現了錯誤四處錯誤:ORA-01858在SQL

ORA-01858: a non-numeric character was found where a numeric was expected

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是一個日期。

但是,如果替換爲:

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

是正確的。

爲什麼它不正確?以及如何修復?

+0

你確定在'p_from_date'輸入的值是'DD-MM-YYYY'嗎? (你改變了你在它工作的例子中的日期格式)。 – Ollie

+0

你不想在where子句中使用IS NULL嗎? – jarlh

+0

我forgor fomat字符串數據類型。我必須是'&p_from_date'或輸入應爲'' –

回答

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); 
+0

謝謝!我忘記了fomat字符串數據類型。 –