Skip to Content
avatar image
-1
Former Member

hana studio indefinitely executes the below query

Hi,

while running the below code hana goes into indefinite run time.

Any help will be appreciated.

CREATE PROCEDURE "FOR_LOOP_EXAMPLE"() LANGUAGE SQLSCRIPT SQL SECURITY INVOKER AS /*********BEGIN PROCEDURE SCRIPT ************/ BEGIN DECLARE v_index INT=1; DECLARE v_index2 INT=1; DECLARE min INT ; DECLARE max INT ; create table t( rownum int, itemcode varchar(50)); Insert into t SELECT Row_Number() OVER (ORDER BY T0."ItemCode" ) as a ,T0."ItemCode" FROM OITM T0 WHERE T0."ItemCode" in('I03515','I04289'); SELECT (SELECT MIN(rownum) FROM t) INTO min FROM DUMMY; SELECT (SELECT MAX(rownum) FROM t) INTO max FROM DUMMY; -- select min as min,max as max FROM DUMMY; FOR v_index IN :min .. :max DO FOR v_index IN 1 .. 1 DO Select v_index from dummy; select * from oitm where "ItemCode" in (Select itemcode from t where rownum=v_index); END FOR; END FOR; -- Select * from t; drop table t; END; CALL "FOR_LOOP_EXAMPLE"();

Regards

Khagesh

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Jun 13, 2017 at 06:21 AM

    Why wouldn't it?

    You explicitly stated that you want a loop over **v_index**

    DECLARE v_index INT=1;
    DO FOR v_index IN 1 .. 1 DO 
        Select v_index from dummy; 
        select * from oitm where "ItemCode" in (Select itemcode from t where rownum=v_index); 
    END FOR; 

    As v_index never gets updated, it stays in the range between 1 and 1 - and the loop never terminates.

    Add comment
    10|10000 characters needed characters exceeded