How to find an unknown duplicate substring in a string or table Coulmn

I have a large string of numbers as input to the program (I think the sequence name is's'). It can be a string or a table column

We simplify the following example: each substring contains three numbers instead of 100

Table 1:

Table 1 Description: each row of Table 1 belongs to one of the substrings repeated in "s" sting For each column, we have exactly ten numbers that belong to that column through randomly repeated numbers For example, for the first column, we can have, for example, four 11 and six 65, or one 11 and nine 65, and so on For a column with one number, every ten repetitions are the number, such as the seventh column, as follows: 50 50 50 50 50 50 50 50 50 50 50 50 50

The output is a repeated substring, forming an "s" string Output:

11,10,13
30,40,50
65,66,61

Who can help me use PL_ SQL or Java to solve the problem

Solution

Here are some PL / SQL that I think can solve the basic problems you described It will expand to what I think is a larger data set, but I have to make some assumptions about splitting numbers into groups The basic process applies to the data, description and results you provide

SET SERVEROUTPUT ON;

DECLARE
    TYPE numbers_t IS TABLE OF INT(2);
    TYPE output_t  IS TABLE OF VARCHAR2(100);

    c_example VARCHAR2(160) := '1111111111111165656510101030306666666666134061134061616161611030303030306666666613131313134040404061505050505050505050506565656565656565656511111166666666666666';
    c_place   INT := 1;
    c_chunk   INT := 1;
    l_numbers numbers_t := numbers_t();
    l_output  output_t  := output_t();
    n binary_integer;

BEGIN
    l_output.EXTEND(3);
    WHILE c_place <= LENGTH(c_example)
    LOOP
        l_numbers.EXTEND(10);
        WHILE c_chunk <= 10
        LOOP
            l_numbers(c_chunk) := SUBSTR(c_example,c_place,2);
            c_place := c_place + 2;
            c_chunk := c_chunk + 1;
        END LOOP;
        c_chunk := 1;
        l_numbers := SET(l_numbers);
        n := l_numbers.FIRST;
        WHILE (n IS NOT NULL)
        LOOP
                CASE
                WHEN l_numbers(n) < 30 THEN l_output(1) := l_output(1) || ',' || l_numbers(n);
                WHEN l_numbers(n) > 50 THEN l_output(3) := l_output(3) || ',' || l_numbers(n);
                ELSE l_output(2) := l_output(2) || ',' || l_numbers(n);
            END CASE;
            n := l_numbers.NEXT(n);
        END LOOP;
        l_numbers.DELETE();
    END LOOP;
    DBMS_OUTPUT.PUT_LINE(TRIM(LEADING ',' FROM l_output(1)));
    DBMS_OUTPUT.PUT_LINE(TRIM(LEADING ',' FROM l_output(2)));
    DBMS_OUTPUT.PUT_LINE(TRIM(LEADING ',' FROM l_output(3)));
END;
/
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>