SapHanaTutorial.Com HOME     Learning-Materials Interview-Q&A Certifications Quiz Online-Courses Forum Jobs Trendz FAQs  
     Explore The World of Hana With Us     
About Us
Contact Us
 Apps
X
HANA App
>>>
Hadoop App
>>>
Tutorial App on SAP HANA
This app is an All-In-One package to provide everything to HANA Lovers.

It contains
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
Tutorial App on Hadoop
This app is an All-In-One package to provide everything to Hadoop Lovers.

It contains
1. Courses on Hadoop - Basics and Advanced
2. Multiple Quizzes on Basics, MapReduce and HDFS
3. Most popular articles on Hadoop
4. Series of Interview questions to brushup your skills
Apps
HANA App
Hadoop App
';
Search
Stay Connected
Search Topics
Topic Index
+
-
SQLScript
+
-
Tables in SAP HANA
+
-
Procedure
+
-
Examples of Procedure
For Loop in Procedure


In this article we will show an example of SAP HANA procedure to show – How to use For Loop.

Introduction:

The For loop iterates a range of numeric values.
BREAK:
Specifies that a loop should stop being processed.
CONTINUE:
Specifies that a loop should stop processing the current iteration, and should immediately start processing the next.

In this example we will define a loop sequence. If the loop value :x is less than 3 the iterations will be skipped. If :x is 5 then the loop will terminate.

Create procedure:

Copy and paste the below script to create the procedure.

----REPLACE <SCHEMA_NAME> WITH YOUR SCHEMA NAME
CREATE PROCEDURE <SCHEMA_NAME>."FOR_LOOP_EXAMPLE"(
        OUT output_var INT)
    LANGUAGE SQLSCRIPT
    SQL SECURITY INVOKER
    AS
/*********BEGIN PROCEDURE SCRIPT ************/
BEGIN
    DECLARE count INT := 0;   
    DECLARE v_index INT;
   
    FOR v_index IN 0 .. 10 DO
        IF :v_index < 3 THEN
            CONTINUE;
        ELSEIF :v_index = 5 THEN
            BREAK;
        ELSE
            count := count + 1;         
        END IF;
    END FOR;
    output_var := count;     
END;

Call procedure:

Call the procedure using below statement.

CALL <SCHEMA_NAME>."FOR_LOOP_EXAMPLE"(?);

The output will be 2.

Continue reading:
Check the next example on Use of Array in Procedure




Support us by sharing this article.



Explore More
Close X
Close X

Leave a Reply

Your email address will not be published. Required fields are marked *

Current day month ye@r *

 © 2017 : saphanatutorial.com, All rights reserved.  Privacy Policy