请求大神看这条查询sql语句怎么写? oracle数据库 - -

2025-01-01 14:04:08
推荐回答(4个)
回答1:

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)

回答2:

几种情况分别用不同的语句
1、selece * from str where id=?

2、selece * from str where name=?
3、selece * from str where id=? and name=?

回答3:

二者都输入,才能正确查询?那只输入一个,会查询到什么?

回答4:

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)