oracle拆分逗号分隔匹配数据

Oracle某列数据是由逗号分隔特情况处理
select bha.*
  from BI_HA_DEMAND_FLOW_ATTACH bha
where bha.idx in(
/**获取某用户所发起的流程,该需求流程所对应上传的附件ID信息列表**/
select substr(x.col_1, x.pos1, x.pos2 - x.pos1 - 1)
  from (select t.col_1,
               level as lv,
               instr(',' || t.col_1 || ',', ',', 1, level) as pos1,
               instr(',' || t.col_1 || ',', ',', 1, level + 1) as pos2
          from (
                /**将附件ID,由列转成行**/
                select wm_concat(bhf.attach_id) col_1
                  from BI_HA_DEMAND_FLOW_INFO bhf) t
        connect by level <=
                   (length(t.col_1) - length(replace(t.col_1, ',', ''))) + 1) x
);
以上这个SQL,为实际运用的,需求基础信息表中仅保存了以逗号为分隔符的附件ID,此时想删除该需求对应的附件内容,则上述SQL则是解决方案,下则SQL则为分解式描述
select wm_concat(bhf.attach_id) from BI_HA_DEMAND_FLOW_INFO bhf;

/**获取某用户所发起的流程,该需求流程所对应上传的附件ID信息列表**/
select substr(x.col_1, x.pos1, x.pos2 - x.pos1 - 1)
  from (select t.col_1,
               level as lv,
               instr(',' || t.col_1 || ',', ',', 1, level) as pos1,
               instr(',' || t.col_1 || ',', ',', 1, level + 1) as pos2
          from (
                /**将附件ID,由列转成行**/
                select wm_concat(bhf.attach_id) col_1
                  from BI_HA_DEMAND_FLOW_INFO bhf) t
        connect by level <=
                   (length(t.col_1) - length(replace(t.col_1, ',', ''))) + 1) x;

猜你喜欢

转载自xiaowei-qi-epro-com-cn.iteye.com/blog/1671274