Skip to content
Advertisement

Oracle SQL Join an ID on a field with a list of IDs some with ranges

First of all, its not my database and I cannot change it:)

This is an oracle database

I have a table with 2 ID fields code and subcode:

I have another table with a code range field that has a comma separated list of codes however some have a range.

I wish to do a join that would pull out:

To note: The first number can change in the range IE 300.010-400.190

The direction I am heading is to combine the Code and subcode into one number like:

Then look at splitting the string in substrings(numbers) and comparing or using find_in_set or something of that nature but I cannot get there. The issue is The CodeRange has as many as 20 different ranges but each one varies in size.

Any help would be appreciated. Thanks

Advertisement

Answer

I had a similar approach to @Barbaros. By splitting the CSVs in Table2 into their own rows, you can then split the ranges into a beginning/end range and the explicit values as the same value for beginning/end, then do a numeric comparison.

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