Isso eu coloco pra vocês avaliarem as coisas estranhas que ocorrem as vezes: Um SELECT com HAVING antes do WHERE !!!
No exemplo abaixo, estou simulando o erro num Oracle 8.0.6 ( 100% bugado). O pior é que na versão 8.1.7.4 isso está funcionando também
SQL> SELECT * FROM V$VERSION;
BANNER
----------------------------------------------------------------
Oracle8 Release 8.0.6.0.0 - Production
PL/SQL Release 8.0.6.0.0 - Production
CORE Version 4.0.6.0.0 - Production
TNS for HPUX: Version 8.0.6.0.0 - Production
NLSRTL Version 3.3.3.0.0 - Production
SQL>
SQL>
SQL> create or replace procedure thomas_loucura
2 is
3 cursor vcur is
4 select me.codmerc
5 from mercean Me,
6 mercfil mf
7 having max(flgbase) = 'N' --- **** ABSURDO ****
8 where me.codmerc = mf.codmerc
9 and mf.codsit <> 'E'
10 group by me.codmerc;
11
12 vtemp number;
13 begin
14
15
16 open vcur;
17 fetch vcur into vtemp;
18 close vcur;
19
20 end;
21 /
Procedure created
SQL>
SQL> EXEC THOMAS_LOUCURA;
PL/SQL procedure successfully completed
SQL>