sqloracleoracle-sqldeveloperdate-formatting

File contains date values as '09-01-2015 14:30:00'. But after importing to oracle table its showing all date values as '20-01-19 3:12:15.00000 PM'


Tried to find issue with below queries:

  1. Tried to check the only year values. But year values itself is false in the table.
select to_char(datetime,'YYYY') from table;
0031

I tried with both date and timestamp datatypes for the column.

I don't understand the actual issue is in csv file or SQL developer. Can anyone help pls me.

  1. original CSV file data
datetime
09-01-2015 14:30:00+05:30
09-01-2015 14:35:00+05:30
09-01-2015 14:40:00+05:30
09-01-2015 14:45:00+05:30
  1. Removed +05:30 by replace all in notepad++ and then imported into table column with TIMESTAMP datatype. In Table Datetime values are displaying as:
datetime
20-01-09 3:14:30.000000000 PM
20-01-15 3:14:55.000000000 PM
20-01-15 3:15:00.000000000 PM
20-01-15 3:15:05.000000000 PM

3.

SELECT * FROM NLS_SESSION_PARAMETERS WHERE parameter LIKE 'NLS_%_FORMAT';
PARAMETER VALUE
NLS_DATE_FORMAT DD-MM-RR
NLS_TIME_FORMAT HH12:MI: SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MM-RR fmHH12: fmMI:SSXFF AM
NLS_TIME_TZ_FORMAT HH12:MI: SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MM-RR fmHH12: fmMI:SSXFF AM TZR

4.Imported through Data Import Wizard enter image description here

Solution:

As @MTO solution https://stackoverflow.com/a/78663198/21575280
I gave FXDD-MM-YYYY HH24:MI in wizard at the time import it worked. enter image description here


Solution

  • Your image shows that the data is in the format:

    09-01-2015 14:30
    09-01-2015 14:35
    09-01-2015 14:40
    09-01-2015 14:45
    

    and the target table format is YYYY-MM-DD HH24:MI:SS.

    The format does not match the data!


    You can see what happens in an SQL query:

    SELECT TO_CHAR(
             TO_DATE(
               '09-01-2015 14:40',
               'YYYY-MM-DD HH24:MI:SS'
             ),
             'YYYY-MM-DD HH24:MI:SS'
           ) AS dt
    FROM   DUAL;
    

    Then the output is 0009-01-20 15:14:40 and the:

    (Everything is wrong except for the month!)


    To solve it, try setting the target format to FXDD-MM-YYYY HH24:MI. FX tells it to use that exact format, including spaces, hyphens and colons which without FX would be considered optional parts of the format model (you can omit the FX and just use DD-MM-YYYY HH24:MI but, just like your current format, it is likely to permissively accept values that are not in the exact format and that may cause issues and it is probably better to fail immediately with an error message than it is to find that you have data that looked okay but is actually invalid).

    fiddle