OPEN curs1 FOR SELECT * FROM leads_client WHERE status = 0;
UPDATE leads_client SET status = 1 WHERE CURRENT OF curs1;
loop
fetch curs1 into r;
if(r.id is nOT NULL) THEN
id := r.id;
return next;
END IF;
if not(found) then exit; end if;
end loop;