Oracle sqlldr timestamp format headache - oracle

I'm struggling to get sqlldr to import a csv data file into my table, specifically with the field that is a timestamp.
The data in my csv file is in this format:
16-NOV-09 01.57.48.001000 PM
I've tried all manner of combinations in my control file and am going around in circles. I can't find anything online - not even the Oracle reference page that details what all the date/timestamp format strings are.
Does anyone know where this reference page is, or what format string I should be using in my control file for this timestamp format.
For reference, this is what I've most recently tried:
load data
infile 'kev.csv'
into table page_hits
fields terminated by "~"
( ...
event_timestamp TIMESTAMP "dd-mmm-yy hh24.mi.ss",
...)

you can try this format:
event_timestamp TIMESTAMP "dd-MON-yy hh.mi.ss.ff6 PM"
You can browse all available formats in the SQL reference documentation.

Related

Oracle sqlldr timestamp format issue

I'm having an issue getting sqlldr to import a DAT file data file into my table, specifically with the field that is a timestamp.
2018-11-02T20:54:38.000000+0000
I've tried all manner of combinations in my control file and am going around in circles. Does anyone know what should be using in my control file for this above timestamp format?
For reference, this is what I've most recently tried:
load data
infile 'feed.dat'
into table cust_acct
fields terminated by "|"
( ...
updateddatetime TIMESTAMP "YYYY-MM-DD-HH24.MI.SS",
...)
The date 2018-11-02T20:54:38.000000+0000 has a time-zone component so you want TIMESTAMP WITH TIME ZONE data type and you have 6 fractional seconds digits so your data type should have precision of 6.
In a DateTime format model you can use double quotes to indicate a literal string and, in sqlldr you can escape the double quotes with a backslash:
updateddatetime TIMESTAMP(6) WITH TIME ZONE "YYYY-MM-DD\"T\"HH24:MI:SS.FF6TZR",
or
updateddatetime TIMESTAMP(6) WITH TIME ZONE "YYYY-MM-DD\"T\"HH24:MI:SS.FF6TZHTZM",

Import CSV File into Oracle using SQL Developer

I am trying to import data from a CSV file into a Oracle GroupSpace table using SQL Developer tool. I am getting errors for Date column. My Date column has Date in the below format.
5/6/2016
4/11/2018
11/6/2017...
I get error that the date column has Invalid or Null Date Formats.
Any pointers on what format date format to use when importing Date column would be greatly appreciated.
Thank you so much!
JH
If you aren't sure that dates are valid (for example, nothing prevents you from entering 5/55/2016 into a CSV file, and that certainly isn't a valid DATE value), you can create a staging table whose columns are of VARCHAR2 datatype - it accepts everything, even garbage like 5/55/2016.
Then, after you load data, write some SQL to find errors, fix them, and then move data into the target table.
Check the CSV data in a text editor and look for which part represents the month (the month value will be in the range 1..12). If you are using US dates then use MM/DD/YYYY, otherwise you should probably use DD/MM/YYYY as the date format. If the data has a mixture of both, then you must separate those files and use a different format for each, or you are likely to get invalid date values in your database.
SQL Developer can help you.
You can try the date format masks in the drop-down. If we can guess it, we'll default to one. For some reason your data...fools us, but you can type your own.
If you get something that 'works' the warnings go away.
If you get it wrong, we'll let you know before you even get to the next step.
You can find all the data format masks here.

Oracle SQLLDR - Load Record with Invalid Date, Replace Invalid Date with Null

There are records in my source text file with invalid date values. The invalid date values are inconsistent in format due to manual entry. I still want to load all of these records, but I want to replace the invalid date value with a null.
Please let me know if/how this is possible via SQLLDR control file commands. I want to avoid creating any custom functions. Something simple that generally refers to errors/exceptions and that works (unlike the below) is ideal:
DATE "MM/DD/YYYY" NULLIF (FROM_DOS=EXCEPTION)
Thanks!
As far as I can tell, that won't go in a single pass. I'd suggest you to try a relatively simple approach:
load the original data "as is"
rows with invalid dates won't be loaded, but will end in the .BAD file
then modify the control file:
source will now be the .BAD file
load NULL into the date column (FILLER might help)
Alternatively, you might use the source file as an external table and write (PL/)SQL against it to load data into the target table. It allows you to actually code whatever you want, but - as you said you don't want to create a custom function (which would decide whether the input data is - or is not - a valid DATE value), I presume you'd rather skip that option.

SQL*Loader Control File Custom Date Format

I need to import from a CSV file in which timestamps are given in the following format
2014-06-14T09:38:29
I tried the following in the control file for SQL*Loader but it doesn't work
TIME DATE "YYYY-MM-DDTHH:MI:SS"
and
TIME DATE "YYYY-MM-DDTHH24:MI:SS"
How can I parse this custom date? The error I get is
ORA-01821: date format not recognized
Try with below code
time date 'YYYY-MM-DD"T"HH24MISS'

How to insert name of file and modified time using batch/shell script and sql loader

I have a requirement to insert bulk data into an Oracle database from a CSV file. Now table columns specs match those of the CSV file's header with the exception of three additional fields in database:
A Primary Key field (for which a simple SEQUENCE.NEXTVAL is called)
A field for the name of the CSV file
A field for the last modified date+time of the file
The following stack question address an extra column issue, but the solution is pretty easy because it used Oracle sysdate which is internally available. I need to pass a parameter from either batch script/shell script.
Insert actual date time in a row with SQL*loader
Can PARFILE help here somehow?
My other alternative would be to do the whole task in two steps by writing a small java code:
Use SQL Loader for bulk upload leaving out data for the filename and
modified time
And then run a separate update statement to populate the newly
created rows
But I'm looking for something which will get the job done in one shot. Any advice??
I'm affraid it's not possible with sqlldr alone.
There is no tools for this in sqlldr.
You'd need some sort of script or a program to dynamically create a .ctl file for each load.
Here is a bash script to help you get started:
#!/bin/bash -xv
readonly MY_FILENAME=$1
readonly DB_BUF_TABLE=$2
readonly SQLLDR_CTL="LOAD DATA
CHARACTERSET UTF8
APPEND INTO TABLE $DB_BUF_TABLE
FIELDS TERMINATED BY ';'(
filename \"$MY_FILE_NAME\",
col_foo,
col_bar
)"
echo "$SQLLDR_CTL" > "loader.ctl"
sqlldr control=loader.ctl parfile=loader.par data="$MY_FILENAME"
sqlldrReturnValue=$?
You'd needsome locking with this.. or path separation for concurrent loads to be sure sqlldr starts with proper ctl file

Resources