Quote:
|
Originally Posted by KimballJohnson
For example, in 'Examples of SQL Procedures' from the DB2 docs, what's going on here?
DECLARE CONTINUE HANDLER FOR NOT FOUND, SQLEXCEPTION, SQLWARNING
BEGIN
SET result_set_end = 1;
END;
I've also seen the continue handler/set combination without a b/e scope block.
|
BEGIN - END just identifies a compound statement. In terms of the condition handlers you describe, if you want your handler to perform multiple actions, you need to group them together as a compound statement.
e.g.
DECLARE CONTINUE HANDLER FOR NOT FOUND, SQLEXCEPTION, SQLWARNING
BEGIN
SET result_set_end = 1;
SET something_else = 0;
END;
Without the BEGIN-END, the handler declaration would assume that only the first action is associated with it.
As to why you have to declare certain types/objects in a particular order, you just do - it's syntax! Again, the syntax rules apply within a BEGIN-END block, so you can declare variables in a new block , even if you've previously declared a cursor.
The issue with cursors referencing a GTT having to be declared in a nested BEGIN-END block isn't entirely clear. There is no real reason why this should be the case (
AFAIK) other than the compiler gets its knickers in a twist otherwise but is easily placated by this simple 'trick'.
If you're having 'scope' problems as you say with GTTs being declared WITH REPLACE, all I can think you really mean is that you need the GTT declaration (for the compiler) but don't really want to run the statement? If this is the case, employ another simple trick and wrap the declaration in a conditional statement that can never be true. The compiler will be happy and your GTT will not get replaced!
HTH