Link to home
Create AccountLog in
Avatar of Amit
AmitFlag for United States of America

asked on

Inserting date and time from a Linux log file

Hi,

I have to insert data from a Linux log file into oracle . One of the field is a data field.

So the data is say 2/ 7/2008 21:17:40:418 Please note the space before 7 in 2/ 7/2008 (so for single digit dates it puts a space before the number so the 15th of the month would be 2/15/2008 but 3rd would be 2/ 3/2008)

 I have this kind of data. Now how can I store this in an oracle database.  Any answers will be greatly appreciated thanks

anshu
Avatar of Jinesh Kamdar
Jinesh Kamdar
Flag of India image

Say, u read the file and store it in a VARCHAR2 variable v_date. Then you can do something like this :

INSERT INTO table_name (date_col)
VALUES (TO_DATE(SUBSTR(REPLACE(v_date, ' ', '0'), 1, 20),'MM/DD/YYYY HH24:MI:SS'));
Avatar of Amit

ASKER

Hi Jinesh,

If I store it as varchar2 then I won't be able to use all the date functions when trying to report on this field right ?

Is there a way that I can handle this exception also and treat this data as date/timestamp as well

thanks
-anshu
ASKER CERTIFIED SOLUTION
Avatar of Jinesh Kamdar
Jinesh Kamdar
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account