K
K
KTG2018-11-14 04:21:00
Oracle
KTG, 2018-11-14 04:21:00

How to filter by occurrence of a part of a string with delimiters in a string with delimiters?

There is a table, let's call it "data_table":
ID | GROUP
-----------------
01 | 'e;z'
02 | 'a;b'
03 | 'o;p'
04 | 'o;p;z'
05 | 'd;f'
And there is a list of values,
a, b, c, d, z.
Which in the query can be represented as: or In fact, the list of values ​​is much wider and can change constantly. The number of rows in the table is the same great set. It is necessary to return all rows from the 'data_table' table that have at least one value from the list in the 'groups' field. Those. to return, from this example, the following lines are subject: Result ---------- 01 | 'e;z' -- as there is 'z' in the list 02 | 'a;b'
select 'a;b;c;d;z' from dual;
select 'a','b','c','d','z' from dual;


-- because the list contains 'a' and 'b'
04 | 'o;p;z' -- because there is 'z' in the list
05 | 'b;f' -- because there is 'b' in the list.
Is it possible to write something like this in one query ( it is allowed to use PL/SQL standard functions )?
UPD: the option to create a table for a list of values, where each value is a string and matched by occurrence, has the right to life, but is not considered.
The list of values ​​can be put into a temporary table using the WITH clause, but so far I have no idea how to expand an indefinite number of columns into rows. Undefined, because the thought of using unpivot or union enumerating 100-1000 values ​​is disheartening.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
d-stream, 2018-11-14
@d-stream

Oak version - banal like.
Normal - still store the data correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question