Home » RDBMS Server » Server Utilities » Loading DATE & TIME using the SQL-LOADER
Loading DATE & TIME using the SQL-LOADER [message #73533] Tue, 18 May 2004 03:27 Go to next message
Ezra Dashtt
Messages: 2
Registered: May 2004
Junior Member
Hellow

From Ezra Dashtt.

E-MAIL: ezra@mail.jct.ac.il

I'am a lecturer in the Jerusalem Colleage Technoligy (JCT). One of my student has a problem to use the SQL-LOADER in order to load table that contains column of  the type DATE & TIME.

I would be gratful if you:

1) Explain us how to create table that contains column  of type DATE&TIME.

2) How to write ASCII data file for thisabove  table.

3) how to write control file in order to load the above data file to the  above table.

 

Yours Sincerly

Ezra Dashtt

 
Re: Loading DATE & TIME using the SQL-LOADER [message #73541 is a reply to message #73533] Wed, 19 May 2004 01:07 Go to previous messageGo to next message
samhita bhattacharya
Messages: 3
Registered: May 2004
Junior Member
if you are using unix environment sometimes date time column will give problem.so user to_date function to populate that column.

like Jdate position(1:8)date "yyyy-dd-mm" "rtrim(ltrim(to_date(jdate))"
Re: Loading DATE & TIME using the SQL-LOADER [message #73542 is a reply to message #73541] Wed, 19 May 2004 05:28 Go to previous messageGo to next message
Ezra Dashtt
Messages: 2
Registered: May 2004
Junior Member
Hellow
samhita bhattacharya !

I will be gratefull if you send me little practical example that contain the way to create a table that contains DATE and TIME (the time is much more important to my students)
Please add little example of ASCII data file that contains data for the above table and finally add the control file that is needed to import the data file to the table above by the SQL-LOADER.

yours sincerly
Ezra Dashtt
Re: Loading DATE & TIME using the SQL-LOADER [message #73794 is a reply to message #73541] Tue, 13 July 2004 06:25 Go to previous messageGo to next message
Joanne
Messages: 3
Registered: December 2002
Junior Member
I have similar question:

I need to load data like this :

20040312, I need to conver it into 2004-Mar-12 during the load...

what I should do in the Unix Oracle 9i envirement ?

Thanks.
Re: Loading DATE & TIME using the SQL-LOADER [message #73795 is a reply to message #73541] Tue, 13 July 2004 06:26 Go to previous messageGo to next message
Joanne
Messages: 3
Registered: December 2002
Junior Member
I have similar question:

I need to load data like this :

20040312, I need to conver it into 2004-Mar-12 during the load... usng SQL Loader

what I should do in the Unix Oracle 9i envirement ?

Thanks.
Re: Loading DATE & TIME using the SQL-LOADER [message #73802 is a reply to message #73794] Wed, 14 July 2004 22:19 Go to previous message
Barbara Boehmer
Messages: 9101
Registered: November 2002
Location: California, USA
Senior Member
Oracle date columns, which include a time compenent, are not stored in a particular format. The formatting is done when you view the date, either by the current nls_date_format or by using the to_char function. When you are loading data, you need to use the to_date function in your SQL*Loader control file and include the format that the data in your text data file is in. In your example, you will need 'yyyymmdd' in your control file and 'yyyy-Mon-dd' either in your to_char or nls_date_format. Please see the examples below. The first example is for date only and the second is for a date that includes a time component.

scott@ORA92> -- create table with column of date datatype:
scott@ORA92> create table test_table (date_and_time date)
  2  /

Table created.


scott@ORA92> -- contents of text data file test.dat:
20040312


scott@ORA92> -- contents of SQL*Loader control file test.ctl
scott@ORA92> -- that uses to_date function with format of data in control file:
LOAD DATA
INFILE 'test.dat'
REPLACE
INTO TABLE test_table
(date_and_time position (1:8) "to_date(:date_and_time,'yyyymmdd')")


scott@ORA92> -- load data into table test_table
scott@ORA92> -- from text data file test.dat
scott@ORA92> -- using SQL*Loader control file test.ctl:
scott@ORA92> host sqlldr scott/tiger control=test.ctl log=test.log


scott@ORA92> -- view results:
scott@ORA92> select * from test_table
  2  /

DATE_AND_
---------
12-MAR-04


scott@ORA92> -- view results with date column in desired format by using to_char function:
scott@ORA92> select to_char (date_and_time, 'yyyy-Mon-dd') from test_table
  2  /

TO_CHAR(DAT
-----------
2004-Mar-12


scott@ORA92> -- change nls_date_format to desired format:
scott@ORA92> alter session set nls_date_format = 'yyyy-Mon-dd'
  2  /

Session altered.

scott@ORA92> -- view results with date column in new nls_date_format without to_char:
scott@ORA92> select * from test_table
  2  /

DATE_AND_TI
-----------
2004-Mar-12



The following additional example includes a time component.

scott@ORA92> -- create table with column of date datatype:
scott@ORA92> create table test_table (date_and_time date)
  2  /

Table created.


scott@ORA92> -- contents of text data file test.dat:
20040312231136


scott@ORA92> -- contents of SQL*Loader control file test.ctl
scott@ORA92> -- that uses to_date function with format of data in control file:
LOAD DATA
INFILE 'test.dat'
REPLACE
INTO TABLE test_table
(date_and_time position (1:14) "to_date(:date_and_time,'yyyymmddhh24miss')")


scott@ORA92> -- load data into table test_table
scott@ORA92> -- from text data file test.dat
scott@ORA92> -- using SQL*Loader control file test.ctl:
scott@ORA92> host sqlldr scott/tiger control=test.ctl log=test.log


scott@ORA92> -- view results:
scott@ORA92> select * from test_table
  2  /

DATE_AND_
---------
12-MAR-04


scott@ORA92> -- view results with date column in desired format by using to_char function:
scott@ORA92> select to_char (date_and_time, 'yyyy-Mon-dd hh24:mi:ss') from test_table
  2  /

TO_CHAR(DATE_AND_TIM
--------------------
2004-Mar-12 23:11:36


scott@ORA92> -- contents of text data file test.dat:
20040312
0
Previous Topic: How can I move a table with a LONG column to another tablespace?
Next Topic: SQL LOADER NOT INSERTING ALL THE DATA PLZ HELP!
Goto Forum:
  


Current Time: Wed Dec 25 08:16:20 CST 2024