SQL> select count(*) from t where 1=1; COUNT(*)
----------
0已用时间: 00: 00: 00.10
SQL> select decode(count(*),0,1,count(*)) from t where 1=1;DECODE(COUNT(*),0,1,COUNT(*))
-----------------------------
1已用时间: 00: 00: 00.10
SQL>
----------
0已用时间: 00: 00: 00.10
SQL> select decode(count(*),0,1,count(*)) from t where 1=1;DECODE(COUNT(*),0,1,COUNT(*))
-----------------------------
1已用时间: 00: 00: 00.10
SQL>
select decode(count(*),0,1,count(*)) from t where 1=2;
这种条件不成立的情况,它也是返回1啊,达不到我的要求
为什么要用or 呢?
还是很感谢大家!
t表没记录
select decode('s','s',1,count(*)) from t where 字段=某个值
1
select decode('s','k',1,count(*)) from t where 字段=某个值
0
t表有n条记录
select decode('s','s',1,count(*)) from t where 字段=某个值
1
select decode('s','k',1,count(*)) from t where 字段=某个值
n
select nvl(count(*),1) from a where ('S'='S')