| |

VerySource

 Forgot password?
 Register
Search
View: 1205|Reply: 8

I would like to jump out of the current loop in the loop cursor and enter the next cursor loop, how to achieve it?

[Copy link]

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-20 09:40:01
| Show all posts |Read mode
E.g:

for c1 in cursor1 loop

  if a = 1 then jump out;
 
  -Processing statements;

end loop;

How does the "jump out" realize the function of continue?
Thank you very much!
Reply

Use magic Report

0

Threads

39

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 Canada

Post time: 2020-1-29 21:00:01
| Show all posts
exit;

How does the "jump out" realize the function of continue?
Do you want to jump out or continue?
Reply

Use magic Report

0

Threads

39

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-29 22:27:01
| Show all posts
BEGIN
FOR i IN 1..5
LOOP
 IF i> 3 THEN EXIT;
 ELSE
  DBMS_OUTPUT.PUT_LINE (TO_CHAR (i));
  END IF;
END LOOP;
END;
----
1
2
3
Reply

Use magic Report

0

Threads

71

Posts

50.00

Credits

Newbie

Rank: 1

Credits
50.00

 China

Post time: 2020-2-1 20:18:01
| Show all posts
exit is completely out
Reply

Use magic Report

0

Threads

10

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-2-14 23:45:02
| Show all posts
The jump in Oracle is implemented by GOTO. Generally, this command is not recommended.

for cl in cursor1 loop
   if .. then
      goto cursor2_loc; --Go to the specified position
   end if;
end loop;

<< cursor2_loc >>-define the location of a jump
for c2 in cursor2 loop
    ..
end loop;
Reply

Use magic Report

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-4-23 12:30:01
| Show all posts
The subject of my question is
"Why do you want to jump out of the current loop and enter the next cursor loop in the loop cursor?"

The goal I want to achieve is "to jump out of the current loop and enter the next loop"

But using exit is to exit the entire loop, and I want to continue the loop below.

In addition to the above goto, how can it be done concisely? Thanks a lot!
Reply

Use magic Report

0

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-4-28 17:30:01
| Show all posts
for c1 in cursor1 loop

  if a = 1 then do nothing
  else
  -Processing statements;

end loop;

If it meets the exit condition, it will do nothing and continue to loop. This is not enough!
Reply

Use magic Report

0

Threads

39

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-4-30 22:45:01
| Show all posts
BEGIN
FOR i IN 1..5
LOOP
 IF i <> 3 THEN
  DBMS_OUTPUT.PUT_LINE (TO_CHAR (i));
  END IF;

END LOOP;
END;

-------------------------
If it meets the exit condition, it will do nothing and continue to loop. This is not enough!
Reply

Use magic Report

0

Threads

71

Posts

50.00

Credits

Newbie

Rank: 1

Credits
50.00

 China

Post time: 2020-5-3 01:45:02
| Show all posts
Consider using if conditions instead.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list