o.en_branch_no
是逗号分隔的字符串,所以使用正则匹配;
wm_concat(a.branch_name)
是拼接返回结果集,因为子查询返回的结果集是多行
方式一:
select o.en_branch_no,(select wm_concat(a.branch_name) from user1.allbranch a where regexp_like(',' || o.en_branch_no||',', ','||a.branch_no||',') ) from user1.operatorinfo o
方式二:
select o.en_branch_no,(select wm_concat(a.branch_name) from user1.allbranch a where instr(',' || o.en_branch_no||',', ','||a.branch_no||',')>0 ) from user1.operatorinfo o
wm_concat()在一些版本中已经被废弃,所以可以使用listagg()函数代替
方式三:
select o.en_branch_no,(select LISTAGG(to_char(a.branch_name),',') within group (order by a.branch_name) from user1.allbranch a where instr(',' || o.en_branch_no||',', ','||a.branch_no||',')>0
) from user1.operatorinfo o