Date format for SQL*Loader - sql

I am trying to import a file of records into a table and am getting
Rejected - Error on table FUNDPRICE_TEST, column FUNDDATE.
ORA-01843: not a valid month
I did some research and read that Oracle by default expects dates formatted yyyymmdd. Clearly this would throw an error when the first day value (the first record in my case) is more than 12.
How can I format the date in my exported csv file from mm/dd/yyyy 00:00:00 to this yyyymmdd format?
This is of course assuming this is my issue. I could be barking up the wrong tree.
Here is the ctl file after trying date formatting:
load data
infile 'commands/FundPriceDataNEW2.txt'
into table FundPrice
fields terminated by "," optionally enclosed by '"'
( FUND, FUNDDATE DATE "mm/dd/yyyy HH24:MI:SS", FAV, FUNDVALUE )
Here are a few records from the FundPriceDataNEW2.txt:
16,9/30/1999 0:00:00,"999999",9.64
16,10/31/1999 0:00:00,"999999",10.06
16,11/30/1999 0:00:00,"999999",10.40
the order is fund,funddate,fav,fundvalue. The error is on the date saying the format is invalid.

FUNDDATE DATE "mm/dd/yyyy HH24:MI:SS"
In your control card (Control file), try adding the above format for your Date column.

Related

SQL - Date format conversion issue (AUTO to 'MM/DD/YYYY')

In Snowflake, I have a column in a created table called "Date1", that has dates formatted as AUTO (ex. 2022-06-17). I am trying to query that column, but need the date formatted as 'MM/DD/YYYY', yet everything I've tried returns an error of some kind.
When I try date(Date1, 'MM/DD/YYYY) the error says that it can't parse 2022-06-17 for MM/DD/YYYY. When I try to_date(Date1 [MM/DD/YYYY]) or try_to_date(Date1 [MM/DD/YYYY]) the error says it doesn't recognize MM.
Any thoughts?
If you're trying to display the date using a specific format, you're converting to a varchar rather than a date:
select to_varchar(current_date, 'MM/DD/YYYY');
If you're trying to compare a column with a date to a formatted string in MM/DD/YYYY format then:
select current_date = try_to_date('08/04/2022', 'MM/DD/YYYY');
You should try to provide correct format to match 2022-06-17 literal:
SELECT TRY_TO_DATE(Date1, 'YYYY-MM-DD')
FROM tab_name;
Your column is already of type DATE. TO_DATE() and TRY_TO_DATE() convert non-date formats (string, integer) to a DATE type. They are not a means to format your DATE for presentation.
Date data type and presentation format are indepent.
You can alter your session to change the default display format of a date, but the underlying representation in the database remains the same.
alter session set DATE_INPUT_FORMAT='MM/DD/YYYY';
alter session set DATE_OUTPUT_FORMAT='MM/DD/YYYY';
select <col_name> from table; -- Now will show as MM/DD/YYYY for date columns

Getting Error : "Invalid date: [19/8/2013]. The row will be skipped in informatica

We have a source as a flat file which consists of a date column in format 19/08/2013.
We have a target in oracle table which consists of a date column in format 11-AUG-13.
When we are trying to pass the source column value in target using expression TO_DATE AND
TO_CHAR like
**source column is A ---> Source column
v1=TO_CHAR(A)
O1(output column)=TO_DATE(V1,'DD-MON-YY') we are getting the below error.
Invalid date: [19/8/2013]. The row will be skipped.**
Can anyone please help where I'm going wrong.
Thank you
You need to convert the str to date properly and then infa will load them.
Change the mapping like this -
Change data type in source to a string. read data as string.
Then use your expressions but change the to_date function like below.
v1(var column, data type string)=A
O1(output column, data type date)=IIF(IS_DATE(V1,'DD/MM/YYYY'), TO_DATE(V1,DD/MM/YYYY'),null)
IS_DATE - will check if the data is a date or not, if yes then only it will try to convert to a proper date else put null.
3. Then connect O1 column to a date type in oracle target.
This will make sure all data are loaded and none skipped.

Converting VarChar Column with multiple date format to single date column with proper format

I have data of transaction dates in one column within varchar format.
This column contains three separate formats of date in dd-mm-yy, dd/dd/yyyy and third format in dd/mm/yyy format with missing the last digit.
How to modify this column in the correct date format column with the dd-mm-yyyy format.
Add a date column and fill with your convert statement to get the desired format. Once everything looks okay you can drop the text column and rename the new proper date column to match the original.

I have DD-MON-RR HH24.MI.SS format date to get inserted in oracle table, how can I define the DATE in CTL file?

SQL CTL : I have DD-MON-RR HH24.MI.SS format date to get inserted in oracle table, how can I define the DATE in CTL file?
Have defined date in ctl file as
C_DATE DATE "DD-MON-YY HH24:MI:SS"
I have no error in logs, but data inserted in table is in another format. Please guide which format should I give in CTL file to get the date inserted in correct format.
A DATE field has not format itself. What you see is the data from default NLS_DATE_FORMAT setting of your current session.
NB, when your date format is DD-MON-RR HH24.MI.SS why do you declare it as DD-MON-YY HH24.MI.SS?
Your year values might be 0020, instead of 2020

Import date time into Oracle DB using SQL Developer format- "6/26/2018 12:41:00 PM"

I am trying to import data from CSV file in to Oracle Table.
One of the column is DATETIME,
with an example value- "6/26/2018 12:41:00 PM"
(With 2 spaces between date and time)
In Data Import Wizard --> Column Definition --> Data Type
I select "Data Type" as Timestamp.
What should select in the below fields-
Size/Precision- ?? (I tried different sizes like 15, 23, 25,50 )
Format- ?? (I tried various formats- MM/DD/YYYY HH:Mi:SS AM, MM/DD/YYYY HH:Mi:SS)
Please advise.
Thanks!
Try below format in database and also in excel
Import DB: while loading in table MM/DD/YYYY HH:MI:SS AM in sql developer using import.
CSV file : Also format the csv file date field with format using custom m/d/yyyy h:mm:ss AM/PM
Make sure it's stored as a date and not as a VARCHAR2.
Then put in a valid NLS_DATE_FORMAT, so we know how to properly insert the record. For your sample, this will do: MM/DD/YYYY HH:MI:SS AM
We validate the format, so you can see there's no warning next to the list of dates we are previewing below.
One might consider this question a duplicate of sorts...
But you're not dealing with the RAW INSERT statement, our GUI is, and this is how you tell us that same information.
For my .csv file with the date value as "6/26/2018 12:41:00 PM"
select the DATE (No timestamp) and used format- MM/DD/YYYY HH24:MI and it worked for me probably I have all 00 values in my time (SS).