ORA-00900: invalid SQL statement on to_date in oracle - sql

I get an error in a INSERT. The problem is in this line:
to_date('05-JUN-13 01.09.10.000000 PM','DD-MON-YY HH.MI.SS.FF')
I don't know how resolve it. I tried also with
to_timestamp('05-JUN-13 01.09.10.000000 PM','DD-MON-YY HH.MI.SS.FF')
But i had this error:
ORA-01830: date format picture ends before converting entire input string
Any helps? Thanks a lot

The AM/PM format is missing, therefore the "date format picture" (what a wonderful name!) ends too early. Just use
to_timestamp('05-JUN-13 01.09.10.000000 PM', 'DD-MON-YY HH.MI.SS.FF6 AM')

Related

Converting Varchar2 to Date or Time_Stamp invalid month?

I am trying to convert a varchar2(30) of this format
10/10/2019 08:09:48 AM
into date_time or date so I can order it by start_time. I tried the following
SELECT MIN(TO_DATE(START_TIME,'MON/DD/YYYY HH:MI:SS'))
I think it works because no syntax errors but I keep getting "not a valid month" that time structure up there is how the data looks I dont see an obscure date format.
Any ideas what the issue is?
this is for SQL ORACLE DEVELOPER
MON is for "Jan - Dec". Use MM:
SELECT MIN(TO_DATE(START_TIME,'MM/DD/YYYY HH:MI:SS'))
You will also need to account for your "AM/PM" part:
SELECT MIN(TO_DATE(START_TIME,'MM/DD/YYYY HH:MI:SS AM'))
If this does not work out of the box, try explicitly setting the language to American:
SELECT MIN(TO_DATE(START_TIME, 'MM/DD/YYYY HH:MI:SS AM', 'NLS_DATE_LANGUAGE=American'))

SQL Query Error: date format picture ends before converting entire input into string

I'm getting an Error when I run the query below:
to_date('30-APR-19 09.53.35.000000 AM', 'DD-Mon-yy hh24.mi.ss')
Date format picture ends before converting entire input into string
Can I get an assistance please
The major problem you've got is that your date-and-time string can't be parsed using TO_DATE - you'll need to use TO_TIMESTAMP. The issue is that TO_DATE doesn't recognize the FFn format specifier, which is used to process fractional seconds. This makes sense because DATE values are only accurate to the second. So you'll need to use
TO_TIMESTAMP('30-APR-19 09.53.35.000000 AM', 'DD-MON-YY HH.MI.SS.FF6 AM')
Which will return a TIMESTAMP value. If you really need this to be a DATE rather than a TIMESTAMP you can cast the value to DATE by using
CAST(TO_TIMESTAMP('30-APR-19 09.53.35.000000 AM', 'DD-MON-YY HH.MI.SS.FF6 AM') AS DATE)
dbfiddle here
You can directly use to_date function and miliseconds can be ignored using # as following:
to_date('30-APR-19 09.53.35.000000 AM', 'DD-MON-YY HH.MI.SS.###### AM')
Number of # is equal to number of 0s after dot(.)
db<>fiddle demo
Cheers!!

Why is Oracle returning a Not Valid Month error

Can someone tell me why is this SQL query returning a
ORA-01843. 00000 - "not a valid month"
I now it is wrong but it should be because 2018 is not a valid day. 09 is a valid month. I think..
select to_timestamp('2018-09-05 11:35:41', 'dd/MM/yyyy HH:mi:ss') from dual;
I know that the query is wrong. I just want to know why it isn't saying not a valid day or something like that. the error is now saying that the month is wrong which is false.
The reason is because Oracle is trying to be clever/helpful. So, it is interpreting:
select to_timestamp('2018-09-05 11:35:41', 'dd/MM/yyyy HH:mi:ss') from dual;
---------------------^ddMM
The 20 is interpreted as a valid day. The month then follows.
Oracle is helpfully trying to ignore the separator. Hence, the 18 is an invalid month.
Try this:
select to_timestamp('2012-2012', 'dd/MM/yyyy') from dual
If you "insist" to get an error message related to day then try the FX modifier:
SELECT TO_TIMESTAMP('2018-09-05 11:35:41', 'FXdd/MM/yyyy HH:mi:ss') FROM dual;
Error at line 1
ORA-01861: literal does not match format string
I assume that is the error message you would expect.
Or try a "valid" month, e.g.
SELECT TO_TIMESTAMP('2008-09-05 11:35:41', 'dd/MM/yyyy HH:mi:ss') FROM dual;
Error at line 1
ORA-01830: date format picture ends before converting entire input string

Date Format in Informatica

I am trying to convert a string to date in Informatica as follows
TO_DATE('10/21/2014 0:00', 'MM/DD/YYYY MI:SS')
but it throws an error for incorrect string.
Can Informatica process this date format: MM/DD/YYYY MI:SS? If not, is there any solution to process this date format in Informatica?
You need to use MI:
TO_DATE(FIELD, 'YYYY/MM/DD HH:MI:SS')
Try following (I believe MOHAMMED may be implying same but without actual code snippet it isnt clear)
TO_DATE('10/21/2014 00:00', 'MM/DD/YYYY MI:SS')
What I am thinking is TO_DATE('10/21/2014 0:00', 'MM/DD/YYYY MI:SS'). The timestamp part in the given string is invalid. It should be HH:MI(00:00)...
Try to use the following snippet :
TO_DATE( 'Your_Date', 'MM/DD/YY HH24:MI:SS' )
You can check for more examples on the below link :
to_date_function
There is also a difference between two digit times and single digit times. I usually detect the input and then either reject it using Error() if it doesn't fit the format or add the appropriate leading digits depending on the rules to be applied.

Convert a string date into datetime in Oracle

How can I convert this string date to datetime in oracle.
2011-07-28T23:54:14Z
Using this code throws an error:
TO_DATE('2011-07-28T23:54:14Z', 'YYYY-MM-DD HH24:MI:SS')
How can this be done?
Error report:
SQL Error: ORA-01861: literal does not match format string
01861. 00000 - "literal does not match format string"
*Cause: Literals in the input must be the same length as literals in
the format string (with the exception of leading whitespace). If the
"FX" modifier has been toggled on, the literal must match exactly,
with no extra whitespace.
*Action: Correct the format string to match the literal.
Update:-
TO_DATE('2011-07-28T23:54:14Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')
I only see the date not time in the column
28-JUL-11
Try this:
TO_DATE('2011-07-28T23:54:14Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')
Hey I had the same problem. I tried to convert '2017-02-20 12:15:32' varchar to a date with TO_DATE('2017-02-20 12:15:32','YYYY-MM-DD HH24:MI:SS') and all I received was 2017-02-20 the time disappeared
My solution was to use TO_TIMESTAMP('2017-02-20 12:15:32','YYYY-MM-DD HH24:MI:SS') now the time doesn't disappear.
You can use a cast to char to see the date results
select to_char(to_date('17-MAR-17 06.04.54','dd-MON-yy hh24:mi:ss'), 'mm/dd/yyyy hh24:mi:ss') from dual;