Oracle Illustrated

Feb 21 2010   6:45AM GMT

Migrating from 9i to 11g – CONTINUE



Posted by: Lakshmi Venkatesh
Tags:

Feature available from Oracle 11g

This is used to control program flow within the loop. With earlier versions of Oracle we either need to use IF condition or EXIT from the loop. CONTNUE / CONTINUE WHEN can be used.

How is it currently done?

Oracle 9i
SET SERVEROUTPUT ON SIZE 100000
DECLARE
v_item_num NUMBER := 0;
BEGIN
WHILE ( v_item_num < 200)
LOOP
LOOP
v_item_num := v_item_num + 5;
IF MOD(v_item_num,25) = 0 THEN
EXIT;
END IF;
END LOOP;
Dbms_output.put_line(‘Item number = ‘ || v_item_num);
END LOOP;
END;
/

OUTPUT

Item number = 25
Item number = 50
Item number = 75
Item number = 100
Item number = 125
Item number = 150
Item number = 175
Item number = 200

PL/SQL procedure successfully completed.

Oracle 11g
CONTINUE WHEN
SET SERVEROUTPUT ON SIZE 100000
DECLARE
v_item_num NUMBER := 0;
BEGIN
WHILE ( v_item_num < 200)
LOOP
v_item_num := v_item_num + 5;
CONTINUE WHEN MOD(v_item_num,25) 0;
Dbms_output.put_line(‘Item number = ‘ || v_item_num);
END LOOP;
END;
/


OUTPUT

Item number = 25
Item number = 50
Item number = 75
Item number = 100
Item number = 125
Item number = 150
Item number = 175
Item number = 200

PL/SQL procedure successfully completed.

CONTINUE
SET SERVEROUTPUT ON SIZE 100000
DECLARE
v_item_num NUMBER := 0;
BEGIN
WHILE ( v_item_num < 200)
LOOP
v_item_num := v_item_num + 5;
IF MOD(v_item_num,25) 0 THEN
CONTINUE;
END IF;
Dbms_output.put_line(‘Item number = ‘ || v_item_num);
END LOOP;
END;
/
OUTPUT
Item number = 25
Item number = 50
Item number = 75
Item number = 100
Item number = 125
Item number = 150
Item number = 175
Item number = 200

PL/SQL procedure successfully completed.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: