One of the methods:
Setup:
create table emptyTab ( a number);
create table notEmptyTab ( a) as ( select 1 from dual );
This should do the trick:
SQL> select case
2 when count(*) = 0 then 'Pass'
3 else to_char(count(*))
4 end
5 from emptyTab
6 where a = 1 ;
CASEWHENCOUNT(*)=0THEN'PASS'ELSETO_CHAR(
----------------------------------------
Pass
SQL> select case
2 when count(*) = 0 then 'Pass'
3 else to_char(count(*))
4 end
5 from notEmptyTab
6 where a = 1;
CASEWHENCOUNT(*)=0THEN'PASS'ELSETO_CHAR(
----------------------------------------
1
SQL> select case
2 when count(*) = 0 then 'Pass'
3 else to_char(count(*))
4 end
5 from notEmptyTab
6 where a = 2;
CASEWHENCOUNT(*)=0THEN'PASS'ELSETO_CHAR(
----------------------------------------
Pass
source
share