I have large text strings with 10-digit unix date stamps sprinkled throughout. I am trying to write a query to search through the text string for these 10-digit number and replace them with a regular date format. I have the convert statement as:
TRUNC(DATE '1970-01-01' + [timestamp]/86400), which works perfectly when I input a value.
Example:
select TRUNC(DATE ‘1970-01-01’ + 1022089483/86400) from dual; = 22-may-02
But I am having a bad time finding the appropriate way to find and replace. Also, I cannot use regular expressions. So, here’s my theoretical SQL:
replace([column],'[sql to find 10-digit number]'
,TRUNC(DATE '1970-01-01' + [10-digit number]/86400))
Here is some sample text:
1022089483 blah blah blah blah blah 1022094450 blah blah blah blah
blah blah 1022095218 blah blah blah blah
Just for fun, thought I’d try this the hard way. One function to find the start of a 10-digit number using
instr, then one that calls that repeatedly and replaces any that are found with formatted dates. Not at all sure this is a sensible approach, or in any way efficient…There may be other edge cases it trips over, but attmped it with a few obvious ones: