Variables Access in Exception Block.
AnsweredHow hard could it possibly be to expose all declared variables to the exception block?
Would be extremely handy. Please and thank-you.
-
Comment actionsOfficial comment
Hi Chris,
thanks for your request. Variables are local to the block in which they were defined. Let's consider this example:
BEGIN
DECLARE STRING myVar = 'demo';
EXCEPTION e
SELECT myVar;
END;;This snippet throws an error as two blocks are defined here: 1) between BEGIN and EXCEPTION, and 2) between EXCEPTION and END. Variables defined in the first block are not visible in the second one.
If you wish to make variables visible in a broader scope, you can use nested blocks. This example works:
BEGIN
DECLARE STRING myVar;
BEGIN
myVar = 'demo';
RAISE SQLEXCEPTION 123;
EXCEPTION e
SELECT myVar;
END
END;;Best regards
Niklas
Please sign in to leave a comment.
Comments
2 comments