Solved

How to insert some date types with SQLLoader?

Posted on 2014-11-10
6
605 Views
Last Modified: 2014-11-10
Dear Experts,

I have some files with different kinds of data and each file type has different date-time field. I want to load those files with SQLLoader to Oracle tables. In each related Oracle table, there is a field with Date type. However, in the files, representation of date-time fields differs according to file type.  For example one file type has a date-time field with data sample: "2014-11-10 01:07:57". I'will use YYYY-MM-DD HH24:MI:SS for this in control file. Unfortunately not all file types  are easy like this. (See Below) Could you please help for the following?

2014-05-09 12:14:08+02:00DST
2012-01-16 09:24:43.0
2014-11-09 04:00:00 AM
2014-11-8-16-14-55

Thanks in Advance.

BR
0
Comment
Question by:GurcanK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 35

Expert Comment

by:johnsone
ID: 40432455
Not sure I completely understand what you are asking.

Are you asking how to specify the format within the SQL*Loader control file?  That is documented here -> https://docs.oracle.com/cd/E11882_01/server.112/e22490/ldr_field_list.htm#i1016161

Or, are you asking how you can change the mask without changing the control file?  My guess on that (which I have not tested) is that you could set the NLS_DATE_FORMAT in the environment.  I believe that the default format is picked up from there, the documentation doesn't mention the default that I could see.
0
 

Author Comment

by:GurcanK
ID: 40432465
I actually just asked how I can represent these in TO_DATE function such as TO_DATE(VALUE, 'YYYY-MM-DD HH24:MI:SS')

2014-05-09 12:14:08+02:00DST
 2012-01-16 09:24:43.0
 2014-11-09 04:00:00 AM
 2014-11-8-16-14-55
0
 
LVL 35

Accepted Solution

by:
johnsone earned 500 total points
ID: 40432482
The first two are timestamps, not dates, so that would be:

to_timestamp('2014-05-09 12:14:08+02:00DST', 'yyyy-mm-dd hh24:mi:sstxh:tzmtzd')
to_timestamp('2012-01-16 09:24:43.0', 'yyyy-mm-dd hh24:mi:ss.ff1')

If you are inserting into a field with a DATE datatype, the conversion should be done for you automatically.

The rest are:

to_date('2014-11-09 04:00:00 AM','yyyy-mm-dd hh:mi:ss AM')
to_date('2014-11-8-16-14-55','yyyy-mm-dd-hh24-mi-ss')


Documentation for DATE format models -> https://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements004.htm#SQLRF00212
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:GurcanK
ID: 40432486
Thanks, and one last point: Do you mean if I insert those TimeStamp fields (first two of above) to Date field using SQLLOADER then otomatic conversion occurs?

BR
0
 
LVL 35

Expert Comment

by:johnsone
ID: 40432493
Yes.  If you insert a timestamp into a DATE field, then an implicit conversion takes place.  Essentially the subseconds and timezone information is removed.
0
 

Author Comment

by:GurcanK
ID: 40432495
That's great. Best Regards.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question