Four loops in Oracle (GOTO, For, While, Loop)

Source: Internet
Author: User

Four loops in Oracle (GOTO, For, While, Loop)

[SQL] DECLARE x number; BEGIN x: = 9; <repeat_loop> -- cyclic point x: = X-1; DBMS_OUTPUT.PUT_LINE (X); IF X> 0 THEN GOTO repeat_loop; -- when the value of x is less than 9, go to repeat_loop end if; END;/FOR Loop usage in ORACLE [SQL] DECLARE X number; -- DECLARE the variable BEGIN x: = 1; -- give the initial value for x in reverse 1 .. 10 LOOP -- reverse from large to small DBMS_OUTPUT.PUT_LINE ('Internal: x =' | x); end loop; DBMS_OUTPUT.PUT_LINE ('end loop: x = '| X ); -- x = 1 END;/The while loop usage in ORACLE [SQL] DECLARE x number; BEGIN x: = 0; WHILE x <9 LOOP x: = x + 1; DBMS_OUTPUT.PUT_LINE ('internal: x = '| x); end loop; DBMS_OUTPUT.PUT_LINE ('external: x =' | x); END; /LOOP usage in ORACLE [SQL] DECLARE x number; BEGIN x: = 0; LOOP x: = x + 1; EXIT WHEN x> 9; DBMS_OUTPUT.PUT_LINE ('Internal: x = '| x); end loop; DBMS_OUTPUT.PUT_LINE ('outer: x =' | x); END ;/

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.