Teradata - need function a logic to identify patterns in a column

Posted on 2009-12-23
Last Modified: 2012-06-21
Teradata - need a string function/ logic to identify patterns in a column and turn the same into row as the pattern is identified.

A=ABC, B=AC, C=1234, D='Y' is a single column value.

Between = and , whatever value identified should go as column A and same for B, C, D columns.

Question by:ManikandanN
    LVL 20

    Accepted Solution

    with inp
    (select replace('A=ABC, B=AC, C=1234, D=''Y''','''','') src from dual) -- remove quotes if you want
    select src,
    replace(substr(src,1,strA -1),'A=',null) A,    -- use substr to get the part till first comma's
    replace(substr(src,strA + 1,(strb-stra)-1),'B=',null) B, -- use substr to get the part between each pair of comma's
    replace(substr(src,strB + 1,(strc-strb)-1),'C=',null) C, -- use substr to get the part between each pair of comma's
    replace(substr(src,strc + 1),'D=',null) D -- use substr to get part after the 3e comma
    -- use the replace to remove the X=
    (select src,
    instr(src,',',1,1) strA,  -- determine the delimiter positions
    instr(src,',',1,2) strB,
    instr(src,',',1,3) strC,
    instr(src,',',1,4) srtD   -- i made the assumption srtD is always 0 : no ending comma
    from inp

    Author Closing Comment

    I am not an DB expert but the requirment though was complex - solution for the same has been explained neatly with appropriate comments.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
    Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
    This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now