mysql - How to know the last position of a loop? -
i'm using following sql in procedure:
read_loop: loop fetch cur xstatus; if done leave read_loop; end if; set = i+1; if mod 3 = 0 set descrstatus = concat(descrstatus, xstatus, ' | ', char(13)); else if = 1 set descrstatus = concat(xstatus, ' | '); else set descrstatus = concat(descrstatus, xstatus, ' | '); end if; end if; end loop read_loop;
i want know last position of loop.
fetch last value of cursor following query (this should outside loop).
select <column_name> @last_value <table_name> <where_conditions> order <order_column> desc limit 1;
then, add if statement after fetch follows:
if xstatus = @last_value select 'last loop' status; end if;
Comments
Post a Comment