使用nvl判断 SELECT NVL ((select AA from TABLE where a=1),(NVL ((select BB from TABLE where a=1),(select CC from TABLE where a=1) ))) FROM DUAL
tb_name为你的那个表 输入值为 str_name, int_age,str_sex name,age,sex 1)都为空时应该不显示任何数据吧 那就什么都不做! 2)下面是只要有一个不为空的情况 select * from tb_name tb where tb.name like decode(str_name,'','%%','%str_name%') and tb.age like decode(int_age,'','%%',int_age) and tb.sex like decode(str_sex,'','%%',str_sex) 红字部分的代码,sex和age 的处理是一样的,你如与sex=男 ,和你说的age=20性质一样
上面说的第2个处理 也可以用nvl实现 select * from tb_name tb where tb.name like nvl(str_name,'%str_name%') and tb.age like nvl(int_age,'%%') and tb.sex like nvl(str_sex,'%%')
到底是以name为条件,还是name和age都要做为条件呢?
string name,int age,string sex
sql_where varchar2(1024) := 'where 1=1 and ';以后每选中一个条件,在此基础上拼一下就行了。
where instr(name,to_char(x))>0
or to_char(age)=to_char(x) or instr(sex,to_char(x))>0
SELECT NVL ((select AA from TABLE where a=1),(NVL ((select BB from TABLE where a=1),(select CC from TABLE where a=1) ))) FROM DUAL
输入值为 str_name, int_age,str_sex
name,age,sex
1)都为空时应该不显示任何数据吧 那就什么都不做!
2)下面是只要有一个不为空的情况
select * from tb_name tb where tb.name like decode(str_name,'','%%','%str_name%') and tb.age like decode(int_age,'','%%',int_age) and tb.sex like decode(str_sex,'','%%',str_sex)
红字部分的代码,sex和age 的处理是一样的,你如与sex=男 ,和你说的age=20性质一样
select * from tb_name tb where tb.name like nvl(str_name,'%str_name%') and tb.age like nvl(int_age,'%%') and tb.sex like nvl(str_sex,'%%')