2017-07-18 3 views
0

ich eine Abfrage und Apfel CASE funcation habe und immer FehlerEingang Jahr im angegebenen Bereich

(full) year must be between -4713 and +9999, and not be 0

Dieser Code wird Nachgeben der Fehler:

NVL(  
CASE WHEN Ea.ASGACTSTART < add_months(SYSDATE,-12) THEN 365 
ELSE 
to_number(to_char(to_date('1','J') + 
((SYSDATE -1) - Ea.ASGACTSTART), 'J')) 
END , 0) "Adujsted Days", 
+0

Was ist der Zweck von 'to_number (to_char (to_date ('1', 'J')'? –

Antwort

0

Ich glaube, Sie einfach

machen
CASE WHEN Ea.ASGACTSTART < add_months(SYSDATE,-12) THEN 365 
ELSE NVL(SYSDATE - 1 - Ea.ASGACTSTART, 0) 
END AS "Adujsted Days" 
+0

ja, aber ich brauche Einzelwert nicht die Dezimalzahl –

+0

Was ist ein "single value"? Surround es durch 'TRUNC() 'oder' ROUND() ', wenn nötig. –

+0

Dank i Formel in Excel, aber ich habe nicht in Excel jede Formel benötigen, ist es etwas, das ich Excel-Formel umwandeln in Oracel Abfrage hier ist die Formel, Excel = + IF (ISBLANK (@Enddate), IF ($ StartDate

0

Gegeben:

create table tabby (ASGACTSTART date); 
insert into tabby values (sysdate); 

Das Problem ist, dieser Teil des Ausdrucks:

select 
    to_date('1','J') + ((SYSDATE -1) - Ea.ASGACTSTART) 
from tabby ea; 

Wenn Sie die +-, ändern, dann können Sie sehen, warum es ein Problem gibt.

select 
    --to_date('1','J') + ((SYSDATE -1) - Ea.ASGACTSTART) 
    to_date('1','J') , ((SYSDATE -1) - Ea.ASGACTSTART) 
from tabby ea; 

Gemäß wenigstens one other post, to_date ('1', 'J') dazu bestimmt ist möglich, den kleinstmöglichen Zeitpunkt zurückzukehren. Die rechte Seite der + könnte jedoch negativ sein und daher das RDBMS beschweren.

Der von mir erstellte Anwendungsfall sollte genau das tun.

+0

inkonsistente Datentypen: erwartet DATUM hat DATE JULIAN bekommen –

Verwandte Themen