Skip to content
Advertisement

Split and compare two Strings in Oracle SQL

I have a table with three columns structured as followed:

Now I would like to perform an Oracle-SQL-query which gives me the edit-pattern of the two strings left and right. The result should be as followed:

Al my tries with REGEX_SPLIT and CONNECT BY were not successful. Do you have any ideas how to solve that problem?

Advertisement

Answer

You can create a collection data type:

And then split the strings into collections of words and compare the collections:

So for your test data:

The query outputs:

LEFT                   | RIGHT                        | PATTERN     
:--------------------- | :--------------------------- | :-----------
Kiki Cola 50 ml bottle | Kiki Cola 50 ml bottle       | same        
Kiki Cola 50 ml bottle | 50 ml Kiki Cola bottle       | swapped     
Kiki Cola 50 ml bottle | Kiki Cola 50 ml              | contained in
Kiki Cola 50 ml bottle | Kiki Cola Light 50 ml bottle | contains    
Kiki Cola 50 ml bottle | Coca Cola 50 ml bottle       | not_same    

db<>fiddle here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement