This app is an All-In-One package to provide everything to HANA Lovers.
1. Courses on SAP HANA - Basics, Modeling and Administration
2. Multiple Quizzes on Overview, Modelling, Architeture, and Administration
3. Most popular articles on SAP HANA
4. Series of Interview questions to brushup your HANA skills
In the previous article Local Scalar Variable , we learn about local scope variable in HANA.
In this article we will show how variables scope works in HANA.
SQLScript supports local variable declaration in a nested block. Local variables are only visible in the scope of the block in which they are defined. It is also possible to define local variables inside LOOP / WHILE /FOR / IF-ELSE control structures.
Copy and paste the below script to create the procedure.
-- REPLACE <SCHEMA_NAME> WITH YOUR SCHEMA
CREATE PROCEDURE "<SCHEMA_NAME>"."VARIABLE_SCOPE_EXAMPLE"(
OUT val INT)
READS SQL DATA
DECLARE a INT := 1;
DECLARE a INT := 2;
DECLARE a INT;
a := 3;
val := a;
Call the procedure using below statement.
The output will be 2.
From this result you can see that the inner most nested block value of 3 has not been passed to the val variable.