Home » RDBMS Server » Server Utilities » concatenation using sql loader (9i,)
concatenation using sql loader [message #310865] |
Wed, 02 April 2008 12:29 |
riki
Messages: 12 Registered: April 2008 Location: ny
|
Junior Member |
|
|
Friends, thanks in advance.
I get data in ',' delimitted flat file with date and time fields.Date is DATE datatype and Time is TIMESTAMP datatype..I would like to store my date field with date and time without fractional seconds and time with just the time part .
My control file looks like:
LOAD DATA
infile 'test.dat'
replace INTO TABLE TEST
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
(
START_DATE DATE "dd/mm/yyyy hh24:mi:ss",
START_TIME TIME "dd/mm/yyyy hh24:mi:ss.ff1"
)
My data looks like:
03/10/2008,10:12:30.0
03/02/2008,10:15:00.9
I have to see the data as 03/10/2008 10:12:30 in the START_DATE field and 03/10/2008 10:12:30.0 in my STRAT_TIME field.
How can i concatenate these two fields,yet store them seperately?
regards,
riki.
[Updated on: Wed, 02 April 2008 12:38] Report message to a moderator
|
|
|
|
Re: concatenation using sql loader [message #310868 is a reply to message #310866] |
Wed, 02 April 2008 12:43 |
riki
Messages: 12 Registered: April 2008 Location: ny
|
Junior Member |
|
|
Michel you are true .But that is the control file.If i don't store it as time how can i store the timestamp?
Pardon my ignorance.
I have just started working with oracle.
Regard,
riki.
|
|
|
|
|
|
Re: concatenation using sql loader [message #310896 is a reply to message #310886] |
Wed, 02 April 2008 14:40 |
riki
Messages: 12 Registered: April 2008 Location: ny
|
Junior Member |
|
|
The table descprition is as follows:
Name Type
-------------- -------------
DD NUMBER(2)
TYPE VARCHAR2(12)
NAME VARCHAR2(23)
ID VARCHAR2(18)
SYSTEM_TICKS NUMBER(10)
ZONE VARCHAR2(23)
START_DATE DATE
START_TIME VARCHAR2(11)
the data file is like:
STEP,op8ed01rs,0x0001001901F6EFAD,153434196,GMT,04/02/2008,18:51:50.3
ATTESST,ne8pd01tg,0x0001001901F72244,153480435,GMT,04/02/2008,18:59:42.5
ATTESST,rf8vf01gh,0x0001001901F7241D,153484173,GMT,04/02/2008,19:00:00.5
ATTESST,ws8ga01pa,0x0001001801F7231E,153481359,GMT,04/02/2008,18:59:51.8
STEP,er8ga01,0x0001001901F6ED19,153431976,GMT,04/02/2008,18:51:28.1
STEP,se8ga01tv,0x0001001901F722F9,153483135,GMT,04/02/2008,18:59:50.1
The control file is like:
OPTIONS (ROWS=1000, readsize=12582912, BINDSIZE=12582912, SILENT=FEEDBACK,DISCARDS)
LOAD DATA
infile 'test.dat'
APPEND INTO TABLE TEST
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
(
TYPE,
NAME,
ID,
SYSTEM_TICKS,
ZONE,
START_DATE date "mm/dd/yyyy",
START_TIME ,
DD "to_char(to_date(:START_DATE, 'mm/dd/yyyy'),'dd')"
)
Regards,
riki
|
|
|
|
|
Re: concatenation using sql loader [message #310904 is a reply to message #310901] |
Wed, 02 April 2008 15:47 |
|
Barbara Boehmer
Messages: 9103 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
I am not entirely sure what you want to do or why, so the following demonstrates usage of boundfiller and concatenation for loading the date and time into a date datatype, the time only into a varchar2 data type and the date time and fractional seconds into a timestamp datatype. You can use whatever pieces you decide.
-- test.dat:
STEP,op8ed01rs,0x0001001901F6EFAD,153434196,GMT,04/02/2008,18:51:50.3
ATTESST,ne8pd01tg,0x0001001901F72244,153480435,GMT,04/02/2008,18:59:42.5
ATTESST,rf8vf01gh,0x0001001901F7241D,153484173,GMT,04/02/2008,19:00:00.5
ATTESST,ws8ga01pa,0x0001001801F7231E,153481359,GMT,04/02/2008,18:59:51.8
STEP,er8ga01,0x0001001901F6ED19,153431976,GMT,04/02/2008,18:51:28.1
STEP,se8ga01tv,0x0001001901F722F9,153483135,GMT,04/02/2008,18:59:50.1
-- test.ctl:
OPTIONS (ROWS=1000, readsize=12582912, BINDSIZE=12582912, SILENT=FEEDBACK,DISCARDS)
LOAD DATA
infile 'test.dat'
APPEND INTO TABLE TEST
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
(
TYPE,
NAME,
ID,
SYSTEM_TICKS,
ZONE,
filler_date BOUNDFILLER,
START_TIME ,
DD "to_char(to_date(:filler_date, 'mm/dd/yyyy'),'dd')",
START_DATE "TO_DATE(:filler_date || SUBSTR (:start_time, 1, 8), 'mm/dd/yyyyhh24:mi:ss')",
start_timestamp "TO_TIMESTAMP(:filler_date || :start_time, 'mm/dd/yyyyhh24:mi:ss.ff1')"
)
-- table, load, and results:
SCOTT@orcl_11g> CREATE TABLE test
2 (DD NUMBER(2),
3 TYPE VARCHAR2(12),
4 NAME VARCHAR2(23),
5 ID VARCHAR2(18),
6 SYSTEM_TICKS NUMBER(10),
7 ZONE VARCHAR2(23),
8 START_DATE DATE,
9 START_TIME VARCHAR2(11),
10 start_timestamp TIMESTAMP)
11 /
Table created.
SCOTT@orcl_11g> HOST SQLLDR scott/tiger CONTROL=test.ctl LOG=test.log
SCOTT@orcl_11g> ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS'
2 /
Session altered.
SCOTT@orcl_11g> COLUMN dd FORMAT 99
SCOTT@orcl_11g> COLUMN type FORMAT A7
SCOTT@orcl_11g> COLUMN name FORMAT A9
SCOTT@orcl_11g> COLUMN zone FORMAT A4
SCOTT@orcl_11g> SELECT * FROM test
2 /
DD TYPE NAME ID SYSTEM_TICKS ZONE START_DATE START_TIME START_TIMESTAMP
--- ------- --------- ------------------ ------------ ---- -------------------- ----------- ---------------------------------------------------------------------------
2 STEP op8ed01rs 0x0001001901F6EFAD 153434196 GMT 02-APR-2008 18:51:50 18:51:50.3 02-APR-08 06.51.50.300000 PM
2 ATTESST ne8pd01tg 0x0001001901F72244 153480435 GMT 02-APR-2008 18:59:42 18:59:42.5 02-APR-08 06.59.42.500000 PM
2 ATTESST rf8vf01gh 0x0001001901F7241D 153484173 GMT 02-APR-2008 19:00:00 19:00:00.5 02-APR-08 07.00.00.500000 PM
2 ATTESST ws8ga01pa 0x0001001801F7231E 153481359 GMT 02-APR-2008 18:59:51 18:59:51.8 02-APR-08 06.59.51.800000 PM
2 STEP er8ga01 0x0001001901F6ED19 153431976 GMT 02-APR-2008 18:51:28 18:51:28.1 02-APR-08 06.51.28.100000 PM
2 STEP se8ga01tv 0x0001001901F722F9 153483135 GMT 02-APR-2008 18:59:50 18:59:50.1 02-APR-08 06.59.50.100000 PM
6 rows selected.
SCOTT@orcl_11g>
|
|
|
|
Re: concatenation using sql loader [message #310914 is a reply to message #310910] |
Wed, 02 April 2008 17:06 |
riki
Messages: 12 Registered: April 2008 Location: ny
|
Junior Member |
|
|
It works fine on my test table .But for my original table it gives the date part correctly where as the time part it is rounding it to 12:00:00 AM
DAT file:
STEP,op8ed01rs,0x0001001901F6EFAD,153434196,GMT,04/02/2008,18:51:50.3
ATTESST,ne8pd01tg,0x0001001901F72244,153480435,GMT,04/02/2008,18:59:42.5
ATTESST,rf8vf01gh,0x0001001901F7241D,153484173,GMT,04/02/2008,19:00:00.5
ATTESST,ws8ga01pa,0x0001001801F7231E,153481359,GMT,04/02/2008,18:59:51.8
STEP,er8ga01,0x0001001901F6ED19,153431976,GMT,04/02/2008,18:51:28.1
STEP,se8ga01tv,0x0001001901F722F9,153483135,GMT,04/02/2008,18:59:50.1
CTL file:OPTIONS (ROWS=1000, readsize=12582912, BINDSIZE=12582912, SILENT=FEEDBACK,DISCARDS)
LOAD DATA
infile 'test.dat'
INSERT INTO TABLE TEST
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
TYPE,
NAME,
ID,
SYSTEM_TICKS,
ZONE,
filler_date BOUNDFILLER,
DD "to_char(to_date(:filler_date, 'mm/dd/yyyy'),'dd')",
START_DATE "TO_DATE(:filler_date || SUBSTR (:start_time, 1, 8), 'mm/dd/yyyyhh24:mi:ss')",
start_time "TO_TIMESTAMP(:filler_date || :start_time, 'mm/dd/yyyyhh24:mi:ss.ff1')"
)
RESULT:
2 STEP op8ed01rs 0x0001001901F6EFAD 153434196 GMT 02-APR-2008 00:00:00 02-APR-08 12.00.00.0
2 ATTESST ne8pd01tg 0x0001001901F72244 153480435 GMT 02-APR-2008 00:00:00 02-APR-08 12.00.00.0
2 ATTESST rf8vf01gh 0x0001001901F7241D 153484173 GMT 02-APR-2008 00:00:00 02-APR-08 12.00.00.0
2 ATTESST ws8ga01pa 0x0001001801F7231E 153481359 GMT 02-APR-2008 00:00:00 02-APR-08 12.00.00.0
2 STEP er8ga01 0x0001001901F6ED19 153431976 GMT 02-APR-2008 00:00:00 02-APR-08 12.00.00.0
2 STEP se8ga01tv 0x0001001901F722F9 153483135 GMT 02-APR-2008 00:00:00 02-APR-08 12.00.00.0
am clueless ,what step did i miss on?
Regards,
riki.
[Updated on: Wed, 02 April 2008 19:47] by Moderator Report message to a moderator
|
|
|
Re: concatenation using sql loader [message #310927 is a reply to message #310914] |
Wed, 02 April 2008 20:00 |
|
Barbara Boehmer
Messages: 9103 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
I don't know if you are still using the same table structure that you posted or if you have changed the start_time to timestamp datatype. Any calculated fields need to go at the end, after all other fields. If you are going to name your timestamp data type start_time, then you need to use filler_time or some such other name declared as boundfiller type before that, just as filler_date was declared, in order to use it in calculations. If you are still having problems, then please post all of the matching current pieces: data file, control file, table structure, select from table after loading, and sql*loader log file.
|
|
|
Re: concatenation using sql loader [message #310929 is a reply to message #310914] |
Wed, 02 April 2008 20:05 |
|
Barbara Boehmer
Messages: 9103 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
If your current data structure is:
CREATE TABLE test
(DD NUMBER(2),
TYPE VARCHAR2(12),
NAME VARCHAR2(23),
ID VARCHAR2(18),
SYSTEM_TICKS NUMBER(10),
ZONE VARCHAR2(23),
START_DATE DATE,
START_TIME TIMESTAMP)
/
then your control file should be:
LOAD DATA
infile 'test.dat'
INSERT INTO TABLE TEST
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
TYPE,
NAME,
ID,
SYSTEM_TICKS,
ZONE,
filler_date BOUNDFILLER,
filler_time BOUNDFILLER,
DD "to_char(to_date(:filler_date, 'mm/dd/yyyy'),'dd')",
START_DATE "TO_DATE(:filler_date || SUBSTR (:filler_time, 1, 8), 'mm/dd/yyyyhh24:mi:ss')",
start_time "TO_TIMESTAMP(:filler_date || :filler_time, 'mm/dd/yyyyhh24:mi:ss.ff1')"
)
|
|
|
|
|
Goto Forum:
Current Time: Sat Jan 25 20:01:28 CST 2025
|