Problem:
select STR1 from T1 where STR2 = 'NAME1'
In the above query, STR1 may be in the form {ABC, ABC_1, ABC_2, ..., MNO, XYZ, XYZ_1 ...}.
So let's say I have the following conclusion
ABC_1 MNO XYZ
Now I want to extract all the corresponding STR1 that include the part up to _ # . For example, the expected result for the above example dataset:
ABC ABC_1 ABC_2 MNO XYZ XYZ_1
Note that STR2 is always unique to STR1.
The code is wise. I imagine something like the following:
SELECT STR1 FROM T1 WHERE STR1 LIKE '% (truncate_underscore_part(select STR1 from T1 where STR2 = 'NAME1')) %'
Any idea?
First decision:
select t1.str1 from ( select case when instr( str1, '_' ) > 0 then substr( str1, 1, instr( str1, '_' ) - 1 ) else str1 end prefix from t1 where str2 = 'NAME1' ) prefix_list, t1 where t1.str1 like prefix || '%'
Lovelyvirus
source share