Quantcast
Channel: SCN: Message List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 9165

Re: cursor issue with for update in sap hana

$
0
0

Hi Ramya,

 

You are right. I executed the following code and it seems using "for update" causes the loop to execute once more for the first row at the end. If you remove "for update", then the loop is executed only for the number of records in the table.

 

So two options. 1) Remove "for update". 2) Raise a message with SAP

 

drop table t1;

create table t1 (c1 nvarchar(2), c2 nvarchar(2), c3 nvarchar(2));

insert into t1 (c1, c2, c3) values ('1','r1','b');

insert into t1 (c1, c2, c3) values ('1','r2','c');

insert into t1 (c1, c2, c3) values ('1','r3','b');

insert into t1 (c1, c2, c3) values ('1','r4','b');

 

create table my_log (log_entry nvarchar(50);

 

select * from t1;

 

drop procedure PR_R_CUR_LOOP;

create procedure PR_R_CUR_LOOP()

as

  cursor c_cur for select c1, c2, c3 from t1 where c1 = '1' for update; -- 5 executions in loop

--  cursor c_cur for select c1, c2, c3 from t1 where c1 = '1'; -- 4 executions in loop

  v_count smallint;

begin

v_count := 0;

insert into my_log values ('Start Proc');

for r1 as c_cur do

v_count := :v_count + 1;

insert into my_log values ('Loop Executed - ' ||r1.c2||' - '||:v_count);

end for;

insert into my_log values ('end count value ' ||:v_count);

insert into my_log values ('End Proc');

end;

 

truncate table my_log;

call PR_R_CUR_LOOP;

select * from my_log;

 

 

Regards,

 

Ravi


Viewing all articles
Browse latest Browse all 9165

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>