How to exit the loop in oracle
25,944
Solution 1
-
simple exit
loop --do something; exit; end loop;
-
conditional exit
loop --do something; exit when "condition"; end loop;
3.Exit with cursor variable
exit when v_cursor%notfound;
Solution 2
You can try to use the EXIT statament
The EXIT statement breaks out of a loop. The EXIT statement has two forms: the unconditional EXIT and the conditional EXIT WHEN. With either form, you can name the loop to be exited.
Solution 3
loop
if(var_cnt>=10001) then
exit;
end if;
var_cnt:=var_cnt+1;
end loop;
![Sundararaj Thathan](https://lh5.googleusercontent.com/-mnFs7jdTgDg/AAAAAAAAAAI/AAAAAAAAAAA/B_hKd35Tacw/photo.jpg?sz=256)
Author by
Sundararaj Thathan
Updated on July 09, 2022Comments
-
Sundararaj Thathan almost 2 years
Declare var_cnt number(3):=0; begin loop update t_loan_dtl set loan_closure = 'Y' where rownum <10001; end loop; end;
-
Rahul Tripathi over 8 yearsWhat is
employees
? OP has not mentioned any such table? And why a cursor? -
CandleCoder over 8 yearsI have just given an Example here that How to Exit from a loop
-
Rahul Tripathi over 8 yearsThen you need to explicitly mention that in your answer. Else it becomes very confusing as to what your intent is!
-
Tyler2P over 3 yearsPlease don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes.
-
Nur.B over 3 yearsThe code is very simple. When the variable reaches 10000, the loop exits
-
FrenkyB about 2 yearsHe asked how to exit loop explicitly, with condition met.