Oracle Date subtraction with SQLLDR
-
19-09-2019 - |
Question
I am trying to import NetBackup statistics into Oracle. One field I really want is ACTIVE START, but it isn't available from bpdbjobs -report. What is available is ACTIVEELAPSED, so I want to subtract that from the END TIME on import as follows:
END TIME Format: 26/09/2009 10:46:20 PM
ELAPSED TIME Format: 028:32:35 (which is hours, minutes, seconds)
SQL*Loader Control File (Relevant lines):
ACTIVE_ELAPSED BOUNDFILLER POSITION(261:270),
END_TIME POSITION(271:293) char "to_date(:End_time, 'dd/mm/yyyy hh:mi:ss AM')",
ACTIVE_START EXPRESSION "to_date(:END_TIME, 'dd/mm/yyyy hh:mi:ss AM') - TO_DSINTERVAL(':ACTIVE_ELAPSED')",
My googling informs me that there are no format masks for Interval, so I am currently stumped (Oracle SQL is not my normal gig!)
Jonathan
Solution
you could split the elapsed time and convert it in (fraction of) days, then you can substract it from END_TIME:
to_date(:END_TIME, 'dd/mm/yyyy hh:mi:ss AM')
- substr(:elapsed_time, 1, instr(:elapsed_time, ':') - 1) / 24
- substr(:elapsed_time,
instr(:elapsed_time, ':') + 1,
instr(:elapsed_time, ':', 1, 2) - instr(:elapsed_time, ':') -1) / 24 / 60
- substr(:elapsed_time, instr(:elapsed_time, ':', 1, 2) + 1) / 24 / 60 / 60
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow