岗位代码表:dm_gwgwdm     gwmc
001     系统岗
002     网络岗
003     应用岗用户岗位表: yhgwxx
userdm    gwlist
111       001,002
如何查询出用户111的岗位数据:
  gwdm      gwmc
  001      系统岗
  002      网络岗我写的sql执行不了,请问下是什么问题?如何实现?
select gwdm,gwmc from dm_gw where gwdm in(select gwlist from yhgwxx where userdm='111') 

解决方案 »

  1.   

    select gwdm,gwmc from dm_gw where gwdm in (select gwlist from yhgwxx where userdm='111')?  
      

  2.   


    -----把你的修改一下
    with dm_gw as(
    select '001' gwdm, '系统岗' gwmc from dual union all
    select '002' gwdm, '网络岗' gwmc from dual union all
    select '003' gwdm, '应用岗' gwmc from dual
    ),yhgwxx as
    (
    select '111' userdm,'001,002' gwlist from dual
    )
    select gwdm, gwmc
      from dm_gw
     where gwdm in (select regexp_substr(gwlist, '[^,]+', 1, rownum)
                      from yhgwxx
                     where userdm = '111'
                    connect by rownum <= length(gwlist) -
                               length(replace(gwlist, ',', '') + 1))
      

  3.   


    ------执行结果如下。。
    SQL> with dm_gw as(
      2  select '001' gwdm, '系统岗' gwmc from dual union all
      3  select '002' gwdm, '网络岗' gwmc from dual union all
      4  select '003' gwdm, '应用岗' gwmc from dual
      5  ),yhgwxx as
      6  (
      7  select '111' userdm,'001,002' gwlist from dual
      8  )
      9  select gwdm, gwmc
     10    from dm_gw
     11   where gwdm in (select regexp_substr(gwlist, '[^,]+', 1, rownum)
     12                    from yhgwxx
     13                   where userdm = '111'
     14                  connect by rownum <= length(gwlist) -
     15                             length(replace(gwlist, ',', '') + 1))
     16  ;GWDM GWMC
    ---- ---------
    001  系统岗
    002  网络岗SQL> 
      

  4.   

    select * from dm_gw
    where instr((SELECT gwlist from yhgwxx where userdm='111'),gwdm)>0
      

  5.   


    select gwdm,gwmc from dm_gw 
    where instr((select gwlist from yhgwxx where userdm='111'),gwdm)>0
      

  6.   

    select gwdm,gwmc from dm_gw 
    where instr((select gwlist from yhgwxx where userdm='111'),gwdm)>0
      

  7.   


    这个可以得出结果:
    GWD GWMC
    --- ------
    001 系统岗
    002 网络岗
      

  8.   

    with dm_gw as(
    select '001' gwdm,'系统岗' gwmc from dual union all
    select '002', '网络岗' from dual union all
    select '003', '应用岗' from dual),
    yhgwxx as(
    select 111 userdm,'001,002' gwlist from dual)
    select gwdm,gwmc
    from dm_gw,yhgwxx
    where instr(gwlist,gwdm)>0
    and userdm=111GWD GWMC
    --- ------
    001 系统岗
    002 网络岗