Headache loading timestamp with Oracle Sqlldr - sql

Hi All i'm having an issue loading a file with timestamp values with sqlldr, can anyone please help with an idea?
This is what a line of my file to load with the timestamp looks like :
..... 2014-09-02-00.00.00.
And my ctrl file :
...
...
Field POSITION(1085) TIMESTAMP )
Every record is rejected with the error:
ORA-26041: DATETIME/INTERVAL datatype conversion error

SQL*Loader will try to interpret the string as a timestamp using your default NLS session parameters, which by default will be something like:
select value from nls_session_parameters where parameter = 'NLS_TIMESTAMP_FORMAT';
VALUE
--------------------------------------------------------------------------------
DD-MON-RR HH24.MI.SSXFF
... although yours appears to be something else as that setting gives ORA-01843: not a valid month' with the example string. The log file from the load will also show the format it tried to apply:
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
"<field>" 1085 * , DATETIME DD-MON-RR HH24.MI.SSXFF
Whatever your default format is, it doesn't seem to match the format in the file. You could change the format for the database or with a logon trigger but that's not going to be helpful if you have other sources or outputs that expect the existing format; and you shouldn't rely on NLS settings anyway as they could be different in another environment.
You can supply the timestamp format as part of the field definition:
... Field POSITION(1085) TIMESTAMP "YYYY-MM-DD-HH24.MI.SS")
If your column is timestamp with time zone - suggested by the tags but not the question - then it will be inserted in your session's time zone.
It's more common to specify the position range, though just providing the start position 1085 will work if this is the last field in the record.

Related

Getting Error : "Invalid date: [19/8/2013]. The row will be skipped in informatica

We have a source as a flat file which consists of a date column in format 19/08/2013.
We have a target in oracle table which consists of a date column in format 11-AUG-13.
When we are trying to pass the source column value in target using expression TO_DATE AND
TO_CHAR like
**source column is A ---> Source column
v1=TO_CHAR(A)
O1(output column)=TO_DATE(V1,'DD-MON-YY') we are getting the below error.
Invalid date: [19/8/2013]. The row will be skipped.**
Can anyone please help where I'm going wrong.
Thank you
You need to convert the str to date properly and then infa will load them.
Change the mapping like this -
Change data type in source to a string. read data as string.
Then use your expressions but change the to_date function like below.
v1(var column, data type string)=A
O1(output column, data type date)=IIF(IS_DATE(V1,'DD/MM/YYYY'), TO_DATE(V1,DD/MM/YYYY'),null)
IS_DATE - will check if the data is a date or not, if yes then only it will try to convert to a proper date else put null.
3. Then connect O1 column to a date type in oracle target.
This will make sure all data are loaded and none skipped.

Casting Date type to only display time

In my database(an Oracle 11 database) I have a attribute which is of Date type but has a time in the value for some reason, idk why it is Date type and not DateTime. When I select this " Position_time" Of course it just displays the date but when i attempt a filter on the column more options are shown of the same date for multiple times so a time value is present in this column even though it is of date type.
Link to picture of position_time context
As seen in the image even though the attribute is of type Date it contains a time "component" This is not shown in the overview btw only when i try to filter the column idk of that matters.
Id like to extract this time from my date. I've seen plenty of posts explaining how to extract from a DateTime column but not from a Date. I cannot change the type of this column. Is there any way to achieve this?
for example
select
format(tr.position_time)
from positions
Do you mean like this :
select to_char(to_date(position_time,'dd-mm-yyyy HH24:MI:SS'),
'HH24:MI:SS') time from positions;
if you already passing the date type as parameter then just use to_char function for extract the time from it.
E.g:
Select to_char(position_time,'HH24:MI:SS') from positions;
You would convert to a string:
select to_char(tr_position_time, 'HH24:MI:SS')
from positions;
In Oracle, date datatype consist of date + time.
It is the NLS setting of your IDE which is displaying the data like this.
If you want to show date and time then use:
select
To_char(tr.position_time,'dd-mon-rrrr hh24:mi:ss')
from positions
Or if you want just time portion then use:
select
To_char(tr.position_time,'hh24:mi:ss')
from positions
If you want to see all the dates in your session with time then alter your session's NLS setting.
ALTER SESSION SET NLS_DATE_FORMAT = 'dd-mon-yyyy hh24:mi:ss';
select
tr.position_time -- formatting is not needed
from positions
In your IDE also, there must be setting to change the NLS setting.
Cheers!!

Nifi PutHiveStreaming with null timestamp values

I have the target field type in hive as timestamp and from the source I get the json that has either proper timestamp field or "" or null sometimes. I am converting the source JsonToAvro before using PutHiveStreaming processor. The records with proper timestamp format gets into my hive target table successfully. But those that with ""/null (Empty String set) values show the error - Illegal format. Timestamp format should be" YYYY-MM-DD HH:MM:SS[.fffffffff] ". I know if I can default it to some date when it is null/empty, it works.But I do not want that. I want it to be as null in my target table when it is null. How can I achieve this?

Display time format through Oracle

I wish to view my column time as 'hh24:mi:ss' but even i insert it as to_date('13:00:00','hh24:mi:ss'). It still displays as date format. I have tried different methods to convert and i don't wish to alter the session.
Here's my table created:
CREATE TABLE Test
(
Name VARCHAR2(20),
Description Varchar2(20),
StudyTime Date,
SleepTime Date,
);
Insert:
INSERT INTO Test
VALUES('JUDY','STUDYING AT ABC', (To_Date('01:00:00', 'HH24:MI:SS')),
(TO_DATE('06:35:00', 'HH:MI:SS')));
Display results:
Judy,Studying at abc,11-Nov-2011,11-Nov-2011
Thanks for anyone help!
Your IDE or SQL*Plus settings are displaying the default date format of DD-Mon-YYYY.
Even though you are entering just a time format, oracle will still see it as a full date and time, hence the 11-Nov-2011 date (you need to be aware of this!).
When you then select all columns whichever interface you are using to display the results will show you the character representation of the date columns, if you have not specified what that is it will use the default NLS format settings.
See: http://www.adp-gmbh.ch/ora/admin/nls_levels.html
Either change the NLS date format settings or specify using TO_CHAR what format you want the results.
Try:
SELECT name,
description,
TO_CHAR(studytime, 'HH24:MI:SS') as studytime,
TO_CHAR(sleeptime, 'HH:MI:SS') as sleeptime
FROM test;
N.B. I used HH24 for studytime and HH for sleeptime as you have done in your example when entering your values.
This should disply it in the correct format.

db2 timestamp format not loading

I am trying to bulk-load data with timestamps into DB2 UDB version 9 and it is not working out.
My target table has been created thusly
CREATE TABLE SHORT
(
ACCOUNT_NUMBER INTEGER
, DATA_UPDATE_DATE TIMESTAMP DEFAULT current timestamp
, SCHEDULE_DATE TIMESTAMP DEFAULT current timestamp
...
0)
This is the code for my bulk load
load from /tmp/short.csv of del modified by COLDEL, savecount 500 messages /users/chris/DATA/short.msg INSERT INTO SHORT NONRECOVERABLE DATA BUFFER 500
No rows are loaded. I get an error
SQL0180N The syntax of the string representation of a datetime value is
incorrect. SQLSTATE=22007
I tried forcing the timestamp format when I create my table thusly:
CREATE TABLE SHORT
(
ACCOUNT_NUMBER INTEGER
, DATA_UPDATE_DATE TIMESTAMP DEFAULT 'YYYY-MM-DD HH24:MI:SS'
, SCHEDULE_DATE TIMESTAMP DEFAULT 'YYYY-MM-DD HH24:MI:SS'
...
0)
but to no avail: SQL0574N DEFAULT value or IDENTITY attribute value is not valid for column. Timestamp format in source my data file looks like this
2002/06/18 17:11:02.000
How can I format my timestamp columns?
Use the TIMESTAMPFORMAT file type modifier for the LOAD utility to specify the format present in your data files.
load from /tmp/short.csv
of del
modified by COLDEL, TIMESTAMPFORMAT="YYYY/MM/DD HH:MM:SS.UUUUUU"
savecount 500
messages /users/chris/DATA/short.msg
INSERT INTO SHORT
NONRECOVERABLE
It almost looks like ISO to me.
If you are able to edit the data file and can safely change the slashes to hyphens, (maybe clip the decimal fraction) and DB2 accepts ISO, you're home.