oracle 可选模糊条件查询

来源:互联网 发布:网络460是什么意思 编辑:程序博客网 时间:2024/05/17 06:35
例如现在有 <学生信息表>,查询条件为<学号>,查询时若学号输入参数 :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
原创粉丝点击