I have a stored procedure that selects from a table A values it then uses to select from table B. If the number of rows is less than a threshold, it updates Table A's values and reselects table B.
Select val into v from A;
Select ID from B where total > v;
if (Found_Rows() < 3) then
Update A set val = val +1;
end if;
What I am concerned about is when this stored procedure is hit concurrently and the number of rows is > 3 and the Update is run multiple times.
So first, can this happen? If so how can I prevent this from occurring since Lock isn't allowed in a stored procedure?
Thanks for the info in advance!