oracle 的可选条件模糊查询
时间:2010-07-01 来源:nsq029
例如现在有 <学生信息表>,查询条件为<学号>,查询时若学号输入参数 :stu_no为空则默认查询全部学生信息,若:stu_no 为输入时,进行模糊查询;
要实现上述查询只需要进行条件判断语句即可满足要求查询出结果。
eg:
select * from <学生信息表> where (:stu_no is null or instr(<学号>,:stu_no)>0);
下面分析条件:
if :stu_no is null
then
真 or 假 => 取:select * from <学生信息表>
end
if :stu_no is not null
then
假 or 真 => 取:select * from <学生信息表> where instr(<学号>,:stu_no)>0
end
相关阅读 更多 +