Hi,
I am trying to skip a record if some conditions match in a for loop, what is the exact keyword to use that in PL/SQL.
e.g, -
-
DECLARE
-
..
-
i NUMBER;
-
BEGIN
-
-
FOR i <10
-
LOOP
-
-
IF i = 5
-
-- I want to skip the update statement if i is equal to 5 in this example
-
"Continue"
-
END IF
-
-
UPDATE ABC ....;
-
-
END LOOP;
-
5 53010
With the continue statement you can skip to the next iteration in a loop.
try to use the following sample code -
begin
-
for i in 1..3 loop
-
dbms_output.put_line(’i=’||to_char(i));
-
if ( i = 2 ) then
-
continue;
-
end if;
-
dbms_output.put_line(’ Only if i is not equal to 2 ′);
-
end loop;
-
end;
-
Note: this is a feature of Oracle 11g . So try in that version only.
You can also use the continue when statement to determine when to go to the next iteration in the loop. -
begin
-
for i in 1..3 loop
-
dbms_output.put_line(’i=’||to_char(i));
-
continue when ( i = 2 );
-
dbms_output.put_line(’Only if i is not equal to 2′);
-
end loop;
-
end;
Hi,
I am trying to skip a record if some conditions match in a for loop, what is the exact keyword to use that in PL/SQL.
e.g,
DECLARE
..
i NUMBER;
BEGIN
FOR i <10
LOOP
IF i = 5
-- I want to skip the update statement if i is equal to 5 in this example
"Continue"
END IF
UPDATE ABC ....;
END LOOP;
In case if you want to try out in lower versions of oracle, then try this: -
declare
-
begin
-
for i in 1..10 loop
-
declare
-
my_execp EXCEPTION;
-
BEGIN
-
IF(I = 5) THEN
-
RAISE my_exscep;
-
ELSE
-
UPDATE ABC....;
-
END IF;
-
EXCEPTION
-
WHEN my_excep THEN
-
dbms_output.put_line('dont update now!!');
-
END;
-
END LOOP;
-
END;
-
I have not tested this code. I hope this should help you out to achive your requirement!!
Hi,
I am trying to skip a record if some conditions match in a for loop, what is the exact keyword to use that in PL/SQL.
e.g, -
-
DECLARE
-
..
-
i NUMBER;
-
BEGIN
-
-
END LOOP;
-
Have not used Continue, but the following works -
-
DECLARE
-
..
-
i NUMBER;
-
BEGIN
-
-
FOR i <10
-
LOOP
-
IF i = 5
-
UPDATE ABC ....;
-
END IF
-
END LOOP;
-
Have not used Continue, but the following works -
-
DECLARE
-
..
-
i NUMBER;
-
BEGIN
-
-
FOR i <10
-
LOOP
-
IF i = 5
-
UPDATE ABC ....;
-
END IF
-
END LOOP;
-
yep i agree with you completely, keep it simple. except in this case i think he said no update if its 5 so we'd need IF i <> 5 then
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Harman Sahni |
last post by:
As per this URL
http://msdn.microsoft.com/library/en-us/vjref98/html/14_14.asp?frame=true
conitnue works on for, while, do... I know it works for foreach as well as
I'm using it somewhere.
My...
|
by: Daniel Bass |
last post by:
is there an equivalent key word for C++'s "continue" in VB (.net) in this
context?
CString szLine;
szLine = myReader.ReadLine();
while ( !szLine.IsEmpty() )
{
if ( szLine(0) == '-' )
{
|
by: Jan Schmidt |
last post by:
Hi,
in a nested do-while-loop structure I would like to "continue" the outer
loop. With goto this should be no problem in while-loops. However, for
do-while I cannot get it to work (without a...
|
by: mdh |
last post by:
May I ask the group this somewhat non-focused question....having now
seen "continue" used in some of the solutions I have worked on. ( Ex
7-4 solution by Tondo and Gimpel comes to mind)
Is there a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |