MySQL Forums
Forum List  »  Newbie

Re: no data found syntax
Posted by: Roland Bouman
Date: August 22, 2005 12:09PM

Note on the side, I don't think your select will ever cause such an condition to arise. In mysql, a select like this will cause a resultset to be returned to the calling client.
Had it been a SELECT..INTO the condition would be raised in case of no data. Same goes for a cursor. But this will never reach the exception action.

Anyway, in mysql, you define HANDLERs for CONDITIONs like this:

begin
declare v_dummy char(1);
declare
continue handler -- type of handler, continue or exit
for not found -- use the builtin not found condition
insert into tabl1(col1) values ('A')
;

select col1
into v_dummy
from table1
where col1 = 'A'
;
end;

in this case, we used a builtin condition, not found, but you can define your own.
start reading from here for more info:

http://dev.mysql.com/doc/mysql/en/conditions-and-handlers.html

Another note on the side, why don't you just write it like this:

begin
if (
select count(col1)
from table1
where col1 = 'A'
) = 0 then
insert into table1(col1) values ('A');
end if;
end;
$$

Options: ReplyQuote


Subject
Written By
Posted
August 22, 2005 10:47AM
Re: no data found syntax
August 22, 2005 12:09PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.