while (true)
{
// do something
if (exit_condition)
break;
}
DECLARE
BEGIN
LOOP
// do something
IF exit_condition THEN
EXIT;
END IF;
END LOOP;
END;
/
while (condition)
{
// do something
}
DECLARE
BEGIN
WHILE condition LOOP
// do something
END LOOP;
END;
/
for (int i=0; i>length; i++)
{
// do something
}
DECLARE
BEGIN
FOR i IN 1..length LOOP
// do something
END LOOP;
END;
/
for (int i=length; i<0; i--)
{
// do something
}
DECLARE
BEGIN
FOR i IN REVERSE 1..length LOOP
// do something
END LOOP;
END;
/
for (object o : objects)
{
// do something
}
DECLARE
TYPE table_nums is TABLE of NUMBER;
nums table_nums;
num NUMBER;
BEGIN
nums := table_nums(4, 8, 15, 16, 23, 42);
FOR ELEM in 1 .. nums.COUNT LOOP
num :=nums(ELEM);
// do something
END LOOP;
END;
/
String objects:
DECLARE
TYPE table_varchars is TABLE of VARCHAR2(size);
strings table_varchars;
str VARCHAR2;
BEGIN
strings := table_varchars('string1', 'string2', 'string3');
FOR ELEM in 1 .. strings.COUNT LOOP
str :=strings(ELEM);
// do something
END LOOP;
END;
/
DECLARE
TYPE table_nums is TABLE of NUMBER;
nums table_nums;
num NUMBER;
BEGIN
SELECT column INTO nums FROM data_table WHERE condition;
FOR ELEM in 1 .. nums.COUNT LOOP
num :=nums(ELEM);
// do something
END LOOP;
END;
/
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)