on 06-10-2017 3:37 PM - last edited on 02-03-2024 11:58 PM by postmig_api_4
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
9 | |
8 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.