-1

I have a , separated string values in two different columns and need to match a specific value between these two columns. Example:

Column A: A123,B234,I555,K987
Column B: AAA1,A123,B234,I555,K987

I want to check the value B234 from Column A (which is starting 6th position) and B234 from Column B (which is starting 11th position), if they are matching or not. I have few hundred of such records and need to check if these values are matching or not.

Barbaros Özhan
  • 39,060
  • 9
  • 21
  • 45
Bruce
  • 65
  • 5

1 Answers1

2

The way you put it, you'd compare "words" - the 2nd one in column A against the 3rd one in column B (sample data in lines #1 - 4; query you might be interested in begins at line #5):

SQL> with test (cola, colb) as
  2    (select 'A123,B234,I555,K987', 'AAA1,A123,B234,I555,K987' from dual union all
  3     select 'XYZ'                , 'DEF'                      from dual
  4    )
  5  select *
  6  from test
  7  where regexp_substr(cola, '\w+', 1, 2) = regexp_substr(colb, '\w+', 1, 3);

COLA                COLB
------------------- ------------------------
A123,B234,I555,K987 AAA1,A123,B234,I555,K987

SQL>
Littlefoot
  • 78,293
  • 10
  • 26
  • 46
  • Thank you @Littlefoot. This works!! – Bruce Feb 19 '21 at 19:53
  • You're welcome. – Littlefoot Feb 19 '21 at 19:55
  • Did you notice the closure of this post? It seems a little off to me. The reference doesn't include Oracle's methods. I expect the only reason for the closure was the added regex tag. – Scratte Feb 25 '21 at 23:06
  • No, I didn't, @Scratte. It is 2 years old and I think that SO doesn't notice us about closed discussions. – Littlefoot Feb 26 '21 at 06:09
  • Not sure what you mean about "2 years old". The Question was asked at "2021-02-19 19:38:09", which was about a week ago. But I cannot vote to reopen, since I don't have the privileges. – Scratte Feb 26 '21 at 08:50
  • 1
    Hahahha! LOL! "Feb 19" was "Feb 2019" to me :) Sorry, @Scratte. My bad. OK, I pushed the "Reopen" for you :) – Littlefoot Feb 26 '21 at 09:16