Archives of the TeradataForum
Message Posted: Mon, 28 Nov 2005 @ 16:26:46 GMT
Subj: | | Re: Exit From Stored Procedure |
|
From: | | Hough, David |
You need to put a label on the first (outermost) BEGIN statement and then use LEAVE to transfer to that label:
replace procedure p(out returncode integer)
exit_label:
begin
...
if (condition) then -- fails
returncode = 0;
leave exit_label;
end if;
...
end;
The LEAVE statement by default (no label) exits only the current block. You can exit any number of levels by targeting specific labels,
and you can make the code pretty obscure if you're not careful. I tend to put a single exit label on the first begin and stop there.
The documentation is unclear on this topic - it took us a long time to figure out why the examples in the manual tended to have a lot of labels
on BEGIN statements. Apparently, the authors felt they should be there as place holders for future leave statements.
/dave hough
|