我有以下" table1" :
NAME JOB
Mary pilot, astronaut, cook
John astronaut, biker
Michael rider
Rita teacher, doctor
我想选择所有宇航员或医生。应该归还Mary,John和Rita。
我目前有:
select name from table1
where 'astronaut,doctor' in (select regexp_substr(table1.job,'[^'',]+', 1, level)
from dual
connect by regexp_substr(table1.job, '[^'',]+', 1, level) is not null)
但是,我不想比较左侧的整个字符串,而是想要迭代它。
注意:我将左手参数作为输入参数,因此必须在sql中解析。
答案 0 :(得分:4)
您应该修复数据格式。您正试图将列表存储在列中,这是一个坏主意。您应该使用联结表而不是分隔值。
有时,我们会遇到其他人糟糕的设计决定。 Oracle确实有强大的正则表达式运算符。这确实允许:
select name, job
from table1
where regexp_like(job, replace('astronaut,doctor', ',', '|');