Home » RDBMS Server » Server Utilities » Extract date from a column in SQL Loader
Extract date from a column in SQL Loader [message #638200] |
Fri, 05 June 2015 16:44 |
|
jimitkr
Messages: 6 Registered: June 2015
|
Junior Member |
|
|
Hi Friends,
I have a column STAT_SESSION_ID in my source file (.dat) which is 30 digits. The first 14 digits in this column are actually a character timestamp as seen below:
201505261048310090000468709941
I am trying to create a control file where one of the fields stores the date extracted from the above id:
The syntax of my date column is as follows:
STAT_SESS_DATE DATE "TO_DATE(SUBSTR(TO_CHAR(:STAT_SESSION_ID), 1, 14), 'YYYYMMDDHH24MISS')",
When i run my script to process incoming data i always get the error:
"ORA-01821: date format not recognized"
What am i doing wrong?
-- text of attached file:
UNRECOVERABLE
LOAD DATA
INFILE '/app_data1/stats/sql_loader_scripts/tmpFile'
APPEND
INTO TABLE stage.stat_match_track_test
fields terminated by "\t"
TRAILING NULLCOLS
(
STAT_SESSION_ID,
STAT_SEQ,
TRACK_ID,
TUI_ID,
ORDINAL,
STAT_SESS_DATE DATE "TO_DATE(SUBSTR(TO_CHAR(:STAT_SESSION_ID), 1, 14), 'YYYYMMDDHH24MISS')",
FEED_TUI_ID,
FEED_DATE,
EXTERNALID,
EXTERNALID_DATASOURCE,
MATCH_POSITION,
)
[mod-edit: text of attached file added to post]
[Updated on: Sat, 06 June 2015 19:49] by Moderator Report message to a moderator
|
|
|
Re: Extract date from a column in SQL Loader [message #638201 is a reply to message #638200] |
Fri, 05 June 2015 17:12 |
Solomon Yakobson
Messages: 3303 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
Your control file has field FEED_DATE. Is corresponding table column data type DATE? IF so, then most likely it is FEED_DATE that's causing error. In any case, if FEED_DATE is DATE your control file should provide explicit date format and not rely on session default.
SY.
|
|
|
|
|
|
|
|
|
|
|
Re: Extract date from a column in SQL Loader [message #638268 is a reply to message #638225] |
Mon, 08 June 2015 13:36 |
|
jimitkr
Messages: 6 Registered: June 2015
|
Junior Member |
|
|
Hi Barbara / Friends,
Here you go.
I'm attaching my source data file with this post.
The script to pick up data from this source file and load to an oracle table is "load_stat_match_track.sh" below:
-------------------------------------------------------------------------------------------------------------------------------------
cd /app_data1/stats/loader
for file in STAT_MATCH_TRACK*
do
sqlldr stage/stage01@gndw control=/app_data1/stats/sql_loader_scripts/stat_match_track.ctl data=/app_data1/stats/loader/$file direct=true
done
------------------------------------------------------------------------------------------------------------------------------------- -------
My control file is as below:
---------------------------------------------------------------------------------------------------------
UNRECOVERABLE
LOAD DATA
APPEND
INTO TABLE stage.stat_match_track_test
fields terminated by "\t"
TRAILING NULLCOLS
(
STAT_SESSION_ID,
STAT_SEQ,
TRACK_ID,
TUI_ID,
ORDINAL,
STAT_SESS_DATE DATE "TO_DATE(SUBSTR(TO_CHAR(:STAT_SESSION_ID), 1, 14), 'YYYYMMDDHH24MISS')",
FEED_TUI_ID,
FEED_DATE,
EXTERNALID,
EXTERNALID_DATASOURCE,
MATCH_POSITION
)
--------------------------------------------------------------------------------------------------
I try to load my data with the command "./load_stat_match_track.sh"
This is the output of the above command:
--------------------------------------------------------------------------------------------------------------
SQL*Loader: Release 11.2.0.4.0 - Production on Mon Jun 8 11:33:58 2015
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
ORA-01821: date format not recognized
SQL*Loader: Release 11.2.0.4.0 - Production on Mon Jun 8 11:33:58 2015
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
ORA-01821: date format not recognized
SQL*Loader: Release 11.2.0.4.0 - Production on Mon Jun 8 11:33:58 2015
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
ORA-01821: date format not recognized
---------------------------------------------------------------------------------------------------------
Also, there is no bad file getting generated in the folder where i run this script. I just get the above error and nothing else.
|
|
|
Re: Extract date from a column in SQL Loader [message #638299 is a reply to message #638268] |
Tue, 09 June 2015 05:53 |
|
Barbara Boehmer
Messages: 9104 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
You have incorrectly combined two different syntaxes for declaring a date in your control file. Change the following line:
STAT_SESS_DATE DATE "TO_DATE(SUBSTR(TO_CHAR(:STAT_SESSION_ID), 1, 14), 'YYYYMMDDHH24MISS')",
to:
STAT_SESS_DATE "TO_DATE(SUBSTR(TO_CHAR(:STAT_SESSION_ID), 1, 14), 'YYYYMMDDHH24MISS')",
|
|
|
Re: Extract date from a column in SQL Loader [message #638403 is a reply to message #638299] |
Wed, 10 June 2015 14:19 |
|
jimitkr
Messages: 6 Registered: June 2015
|
Junior Member |
|
|
Barbara Boehmer wrote on Tue, 09 June 2015 05:53You have incorrectly combined two different syntaxes for declaring a date in your control file. Change the following line:
STAT_SESS_DATE DATE "TO_DATE(SUBSTR(TO_CHAR(:STAT_SESSION_ID), 1, 14), 'YYYYMMDDHH24MISS')",
to:
STAT_SESS_DATE "TO_DATE(SUBSTR(TO_CHAR(:STAT_SESSION_ID), 1, 14), 'YYYYMMDDHH24MISS')",
Removing the keyword "DATE" worked! Is a specific button to close this thread?
|
|
|
|
Goto Forum:
Current Time: Thu Jan 30 20:05:02 CST 2025
|