Stored procs: detecting when SELECT returns no records
Posted in 1995
Topics: Stored Procedures & SPL, Platform-Specific Issues
I am an SQL novice trying to teach myself Informix on AIX using
nothing more than the Informix manuals. While the books seem
pretty good, stored procedures seem to be only BARELY
documented. Much is left to the imagination and trial/error.
What is the proper way, in a stored procedure, to detect when a
single-row SELECT doesn't find a row? The only mechanism
I saw in the manuals was the ON EXCEPTION statement. However,
when I tried it, I observed no exception. What happened instead
was that the variable I was selecting into was set to NULL. Is
that the only indication that a SELECT didn't find a record?
Seems ambiguous unless the column in question has a not-null
constraint.
Basically, here's the *pseudo* code for what I'm trying to do in
this particular procedure. If someone would be kind enough to
suggest the proper way to accomplish this in an Informix stored
procedure, I'll be very grateful:
SELECT quantity FROM history
WHERE history.sku = sku AND history.date = date;
IF no record found
INSERT new record into history table
ELSE
UPDATE quantity in existing record in history table
Andrew Ernest
andrew@infi.net