Variables Access in Exception Block.Answered
How 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
thanks for your request. Variables are local to the block in which they were defined. Let's consider this example:
DECLARE STRING myVar = 'demo';
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:
DECLARE STRING myVar;
myVar = 'demo';
RAISE SQLEXCEPTION 123;
Please sign in to leave a comment.