Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8389683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:47:41+00:00 2026-06-09T18:47:41+00:00

I have large text strings with 10-digit unix date stamps sprinkled throughout. I am

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:47:43+00:00Added an answer on June 9, 2026 at 6:47 pm

    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…

    create or replace function epoch_offset(p_value in varchar2, p_start number)
    return number is
        l_value varchar2(4000);
        offset number := 0;
        prev_offset number := 0;
        digit_count number := 0;
        epoch_start number := 0;
        pos number := p_start;
    begin
        -- replace all digits with a single one, to make searching with instr
        -- simpler
        l_value := translate(p_value, '1234567890', '9999999999');
    
        while true loop
            -- find the next digit, starting as pos; first time through, pos
            -- will be the p_start we were given, then it tracks where we have
            -- got to
            offset := instr(l_value, '9', pos);
    
            if offset = 0 then
                -- we didn't find a digit, check if we already had a 10-digit
                -- number and have just reached the end
                if digit_count = 10 then -- and pos > length(p_value) then
                    -- original value ends with a timestamp; so we have a 10-digit
                    -- number
                    exit;
                else
                    -- no more digits, and last set we saw was short than 10; so
                    -- l_value does not contain any 10-digit numbers (at least,
                    -- after p_start)
                    epoch_start := 0;
                    exit;
                end if;
            end if;
    
            if prev_offset > 0 and offset != prev_offset + 1 then
                -- we've found a digit, but there's a gap since the last one
                if digit_count = 10 then
                    -- the gap denotes the end of a 10-digit number, which is
                    -- what we're looking for
                    exit;
                end if;
    
                -- we've potentially started a new 10-digit number, so reset
                epoch_start := offset;
                digit_count := 0;
                prev_offset := 0;
            else
                -- we've found a sequential digit
                prev_offset := offset;
            end if;
    
            -- mark where we are
            if digit_count = 0 then
                -- start of a potential digit-sequence, make a note
                epoch_start := offset;
            end if;
            digit_count := digit_count + 1;
            pos := offset + 1;
        end loop;
    
        return epoch_start;
    end epoch_offset;
    /
    
    create or replace function epoch_replace(p_value in varchar2,
        p_start in number default 1)
    return varchar2 as
        l_pos number;
        l_time number;
        l_value varchar2(4000);
    begin
        -- for this iteration, find the start of a 10-digit number, starting
        -- from p_start (1 on first iteration, by default)
        l_pos := epoch_offset(p_value, p_start);
        if l_pos > 0 then
            -- found a 10-digit number; call this recursively before modifying -
            -- this means we'll replace numbers with dates working from the end,
            -- so the positions don't need to be adjusted for the difference
            -- between the number and date lengths
            l_value := epoch_replace(p_value, l_pos + 10);
            -- get the 10-digit number...
            l_time := to_number(substr(l_value, l_pos, 10));
            -- ... and convert it to a date, with the rest of the original value
            -- around it
            return substr(l_value, 1, l_pos - 1)
                || to_char(trunc(DATE '1970-01-01' + l_time/86400), 'DD-mon-RR')
                || substr(l_value, l_pos + 10);
        else
            -- didn't find a 10-digit number, so return what we started with
            return p_value;
        end if;
    end epoch_replace;
    /
    

    There may be other edge cases it trips over, but attmped it with a few obvious ones:

    with tmp_tab as (
        select '1022089483 blah blah blah blah blah 1022094450 blah blah blah blah blah blah 1022095218 blah blah blah blah' as value from dual
        union all
        select 'blah 1022089483 blah 1022094450' from dual
        union all
        select 'blah 1022089483 98765 1022094450 1234' from dual
        union all
        select 'blah 1022089483 98765 1022094450 1022095218 1234 123456789 12345678901 123' from dual
    )
    select epoch_replace(value) from tmp_tab;
    
    EPOCH_REPLACE(VALUE)
    ------------------------------------------------------------------------------------------------------------------------
    22-may-02 blah blah blah blah blah 22-may-02 blah blah blah blah blah blah 22-may-02 blah blah blah blah
    blah 22-may-02 blah 22-may-02
    blah 22-may-02 98765 22-may-02 1234
    blah 22-may-02 98765 22-may-02 22-may-02 1234 123456789 12345678901 123
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two large (~100 GB) text files that must be iterated through simultaneously.
I am trying to break a large string of text into several smaller strings
I have a large list of text strings. I know that some strings occur
I have a large text file. I'd like to pick out strings of form
I have a simple application that reads data in small strings from large text
I have a arbitrarily large string of text from the user that needs to
I have a large text file I am reading from and I need to
I have several large text files (30m+ lines, >1GB) which are being processed in
I have a large text file in the format of. english word: spanish equivalent
i have large numbers of text files and i am in problem that i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.