Reputation: 117
I get "Encountered the symbol "IF"" error without any "when expecting ..." after that. My simplified code looks like this:
declare
begin
with ()
select <some value> into My_output
EXCEPTION WHEN NO_DATA_FOUND then
My_output := NULL;
END;
if My_output is not NULL then
<Statement>
end if;
end;
Upvotes: 0
Views: 529
Reputation: 191455
Making some assumptions about the bits you’ve left out, you are ending the PL/SQL block and then have more code. Given your exception handler, it looks like that was supposed to be a sub-block:
declare
My_output <some type>;
begin /* main block */
begin /* sub-block - this was missing */
with ()
select <some value> into My_output
EXCEPTION WHEN NO_DATA_FOUND then
My_output := NULL;
END; /* sub-block */
if My_output is not NULL then
<Statement>
end if;
end; /* main block*/
You could potentially use an aggregate min/max instead of an exception handler, if you know there will zero or one result. That would handle multiple results differently though - this version would get too-many-rows.
If the selected value can’t itself be null, you could also put the <statement>
inside the sub-block instead of its own ‘if’ section.
But both off-topic, and hard to tell how much it’s been simplified of course...
Upvotes: 2