p_id 和 p_name 为参数:
假设p_id 不输入的时候,p_id = 0
select * from str
where (p_id = 0 and id = p_id)
or (p_name = '' and name = p_name)
or (p_id <> 0 and p_name = '' and id = p_id and name = p_name)
几种情况分别用不同的语句
1、selece * from str where id=?
2、selece * from str where name=?
3、selece * from str where id=? and name=?
二者都输入,才能正确查询?那只输入一个,会查询到什么?
select *from t
where (id =p_id and p_name is null) or
(name =p_name and p_id is null) or
(id=p_id and name=p_name)