The EXIT statement terminates a loop while the EXIT WHEN statement terminates a loop when a Boolean expression evaluates to TRUE. In a single loop, combine multiple EXIT WHENs into a single Boolean expression, making the resulting code easier to understand and maintain.
| by | Steven Feuerstein Add to Favorites |
| Requires | Oracle Database 10g or later I write the following incomplete block: DECLARE
l_value PLS_INTEGER := 1;
BEGIN
LOOP
/*EXIT*/
IF l_value = 10
THEN
l_value := NULL;
ELSE
l_value := l_value + 1;
END IF;
END LOOP;
DBMS_OUTPUT.put_line (NVL (l_value, 0));
END;
/Which of the choices, when used in place of the /*EXIT*/ comment, results in a PL/SQL block that will display "0" after execution?
Choice 1 CASE Choice 2 EXIT WHEN l_value IS NULL OR l_value > 10; Choice 3 EXIT IF l_value IS NULL OR l_value > 10;
Choice 4 EXIT WHEN l_value IS NULL;
Choice 5 IF l_value IS NULL OR l_value > 10
Answer PL/SQL has three categories of control statements:
PL/SQL supports three kinds of loops: Simple (a.k.a., basic) loop LOOP statements END LOOP; Note: one of your statements in a simple loop should be EXIT or EXIT WHEN to ensure that you don't end up with an infinite loop. WHILE loop WHILE condition LOOP statements END LOOP; FOR loop FOR iterator IN low_value .. high_value LOOP statements END LOOP; FOR record IN [cursor | (SELECT statement) ] LOOP statements END LOOP; Use the EXIT WHEN statement to exit from a loop (and our recommendation would be to use this only with a simple or basic loop to conform. to the "one way in, one way out" principle) when the conditional expression evaluates to TRUE.
Verification DECLARE Resources Link to Quiz http://plsqlchallenge.com/pls/apex/f?p=10000:659:::NO:659:P659_COMP_EVENT_ID,P659_QUIZ_ID,P659_QUESTION_ID:51189,305831,&cs=149832DFE71FE2F92C5195E7C23D528BA |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27795363/viewspace-746985/ ,如需转载,请注明出处,否则将追究法律责任。