我想根据一个传入的职员编号(从下拉列表中选取),查找该职员的详细信息,若编号为0,即选择全部职员信息,要求用一条sql语句完成这个查询,select user_name,user_no,user_rank,user_sal from users where user_no in( case user_no when '0' then (select distinct user_no from users) else  '0016' end) order by user_name;
--0016 为传入的参数值以上语句怎么不执行为'0'的情况呀?

解决方案 »

  1.   

    select user_name,user_no,user_rank,user_sal from users where user_no = DECODE(INPUT,'0',USER_NO,INPUT)
      

  2.   

    2楼的正解
    LZ你的sql能执行成功吗?我怎么试了好像不行
    改一下:
    select user_name,user_no,user_rank,user_sal from users where user_no =( case user_no when '0' then user_no else  '0016' end) order by user_name;
      

  3.   

    我的意思是若传入的参数(usr_no) 为 '0',则查询所有的记录,可怎么查不出结果呀,select user_name,user_no,user_rank,user_sal from users where user_no in( case user_no when '0'   -- 0 参数$v的值
    then (select distinct user_no from users) else  '0016' end) order by user_name;
    --0 ,0016 为传入的参数$v的值若这样写,怎么查不出结果呀,
    select user_name,user_no,user_rank,user_sal from users where user_no in( case user_no when '0'   -- 0 参数$v的值
    then (select distinct user_no from users) end) order by user_name;