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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -