Oracle字段根据逗号分割查询数据

转载:https://blog.csdn.net/weixin_34281537/article/details/86007096

需求是表里的某个字段存储的值是以逗号分隔开来的,要求根据分隔的每一个值都能查出来数据,但是不能使用like查询。

数据是这样的:

Oracle字段根据逗号分割查询数据_第1张图片

查询的sql如下:

 
  1. select * from (

  2. select guid, regexp_substr(st_responsible, '[^,]+', 1, level) responsible

  3. from tt_cancle_responsible

  4. connect by level <= regexp_count(st_responsible, ',') + 1

  5. and guid = prior guid

  6. and prior dbms_random.value is not null )

  7. where responsible ='wyy';

  8.  

 查询结果如下:

Oracle字段根据逗号分割查询数据_第2张图片

你可能感兴趣的:(sql)