WHEN NO DATA FOUND EXCEPTION - COUNT - MAX Functions [message #319731] |
Mon, 12 May 2008 19:56 |
alexaoracle
Messages: 36 Registered: October 2007
|
Member |
|
|
Hi everyone,
When you use COUNT or MAX functions inside of a sql query, and you have no data on the table, you get the No data found exception.
My question is, if you have more than one sql query and each one uses this functions, in the EXCEPTION block how could you know which sql query, triggered the exception?
Is there a way to control this?
|
|
|
|
|
Re: WHEN NO DATA FOUND EXCEPTION - COUNT - MAX Functions [message #319769 is a reply to message #319734] |
Tue, 13 May 2008 00:22 |
alexaoracle
Messages: 36 Registered: October 2007
|
Member |
|
|
hi, this is so weird I mean, I cant explain it.
You know, I have too many columns on some tables, triggers and a dblink, so for this time in order to make my question clear I made a simple example on this forum to explain what I am needing.
the funny thing is that I finished it, I executed on isqlplus and I don´t get the no data found message
create table green(
id number,
intensity number);
insert into green values(1,100);
insert into green values(2,182);
insert into green values(3,140);
insert into green values(4,110);
create table blue(
freq number,
radix number);
insert into blue values(1, 900);
insert into blue values(2, 905);
insert into blue values(3, 950);
insert into blue values(4, 920);
declare
n number;
m number;
begin
select max(intensity) into n from green where id>5;
select count(radix) into m from blue where freq >5;
exception
when no_data_found then
dbms_output.put_line('Message NFD-: '||sqlerrm);
end;
/
so well I have nothing else to say, only that
mmmmm what? and check my code again
[Updated on: Tue, 13 May 2008 00:24] Report message to a moderator
|
|
|
Re: WHEN NO DATA FOUND EXCEPTION - COUNT - MAX Functions [message #319771 is a reply to message #319769] |
Tue, 13 May 2008 00:33 |
S.Rajaram
Messages: 1027 Registered: October 2006 Location: United Kingdom
|
Senior Member |
|
|
It is because of this
SQL> set feedback 1
SQL> select max(sno) from test_tab where sno > 5;
MAX(SNO)
----------
1 row selected.
SQL> select sno from test_tab where sno > 5;
no rows selected
SQL> select count(sno) from test_tab where sno > 5;
COUNT(SNO)
----------
0
1 row selected.
Regards
Raj
|
|
|
Re: WHEN NO DATA FOUND EXCEPTION - COUNT - MAX Functions [message #319773 is a reply to message #319731] |
Tue, 13 May 2008 00:37 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
Quote: | When you use COUNT or MAX functions inside of a sql query, and you have no data on the table, you get the No data found exception.
|
This is incorrect
SQL> ed
Wrote file afiedt.buf
1 declare
2 x number;
3 begin
4 select max(employee_id) into x
5 from hr.employees
6 where employee_id = 10;
7 dbms_output.put_line('val: '||x);
8* end;
SQL> /
val:
PL/SQL procedure successfully completed.
SQL> ed
Wrote file afiedt.buf
1 declare
2 x number;
3 begin
4 select count(employee_id) into x
5 from hr.employees
6 where employee_id = 10;
7 dbms_output.put_line('val: '||x);
8* end;
SQL> /
val: 0
Count will NOT raise no_data_found it will return 0 (zero)
max will not raise no_data_found it will return a null.
|
|
|
|
|
|