从页面传过来很多的用户id,如:1,2,3,4,5
现在我想通过一条sql语句一次查出这5个id所对应的用户信息,请问如何实现?

解决方案 »

  1.   

    SELECT USERID, USERNAME FROM TB_USERS WHERE USERID IN (1,2,3,4,5)
      

  2.   

    select * from tablename where id in(1,2,3,4,5)
      

  3.   

    create table t1 
    as
    select * from  (
    select 1 id , 'A1' name from dual
    union all
    select 2 id , 'A2' name from dual
    union all
    select 3 id , 'A3' name from dual
    union all
    select 4 id , 'A4' name from dual
    union all
    select 5 id , 'A5' name from dual
    );select * from t1
    where instr(',1,2,3,4,5,',','||id||',') > 0
      

  4.   

    其中instr的两个参数前后都要用分隔符','拼起来,否则可能出现不需要的信息。
      

  5.   

    语句很直接
     where id in(1,2,3,4,5) 
      

  6.   

    动态cursor
    open cursor  for select * from table where col in('||instr||')';
      

  7.   

    select * from t_user where user_id in (1,2,3,4,5);