Hi All,
Request you to please clarify me on the below statements. How the HAVING is working, is it like a WHERE clause. As far, I have studied, HAVING will work only on the GROUP BY.
SQL> ed
Wrote file afiedt.buf
1 declare
2 n number;
3 begin
4 select count(empno) into n from emp having 1=2;
5 dbms_output.put_line(n);
6 exception
7 when no_data_found then
8 dbmS_output.put_line('no problem');
9* end;
SQL> /
no problem
PL/SQL procedure successfully completed.
SQL> select count(empno) from emp having 1=3; --Why HAVING is different here compared to the below statement.
no rows selected
SQL> select count(empno) from emp having ename='SCOTT';
select count(empno) from emp having ename='SCOTT'
*
ERROR at line 1:
ORA-00979: not a GROUP BY expression
SQL>
Another one, how these two are different in execution.
SQL> select count(empno) from emp where 1=2;
COUNT(EMPNO)
------------
0
SQL> select count(empno) from emp having 1=2;
no rows selected
Thanks