Use GoTO to jump out of a loop : GOTO « PL SQL « Oracle PL / SQL

Oracle PL / SQL
1. Aggregate Functions
2. Analytical Functions
3. Char Functions
4. Constraints
5. Conversion Functions
6. Cursor
7. Data Type
8. Date Timezone
9. Hierarchical Query
10. Index
11. Insert Delete Update
12. Large Objects
13. Numeric Math Functions
14. Object Oriented Database
15. PL SQL
16. Regular Expressions
17. Report Column Page
18. Result Set
19. Select Query
20. Sequence
21. SQL Plus
22. Stored Procedure Function
23. Subquery
24. System Packages
25. System Tables Views
26. Table
27. Table Joins
28. Trigger
29. User Previliege
30. View
31. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL / SQL » PL SQL » GOTO 
Use GoTO to jump out of a loop
   

SQL>
SQL> CREATE TABLE MyTable (
  2    num_col    NUMBER,
  3    char_col   VARCHAR2(60)
  4    );

Table created.

SQL>
SQL> DECLARE
  2    v_Counter  BINARY_INTEGER := 1;
  3  BEGIN
  4    LOOP
  5      INSERT INTO MyTable
  6        VALUES (v_Counter, 'Loop count');
  7      v_Counter := v_Counter + 1;
  8      IF v_Counter > 50 THEN
  9        GOTO l_EndOfLoop;
 10      END IF;
 11    END LOOP;
 12
 13    <<l_EndOfLoop>>
 14    INSERT INTO MyTable (char_col)
 15      VALUES ('Done!');
 16  END;
 17  /

PL/SQL procedure successfully completed.

SQL>
SQL> select from MyTable;

   NUM_COL CHAR_COL
---------- ------------------------------------------------------------
         Loop count
         Loop count
         Loop count
         Loop count
         Loop count
         Loop count
         Loop count
         Loop count
         Loop count
        10 Loop count
        11 Loop count

   NUM_COL CHAR_COL
---------- ------------------------------------------------------------
        12 Loop count
        13 Loop count
        14 Loop count
        15 Loop count
        16 Loop count
        17 Loop count
        18 Loop count
        19 Loop count
        20 Loop count
        21 Loop count
        22 Loop count

   NUM_COL CHAR_COL
---------- ------------------------------------------------------------
        23 Loop count
        24 Loop count
        25 Loop count
        26 Loop count
        27 Loop count
        28 Loop count
        29 Loop count
        30 Loop count
        31 Loop count
        32 Loop count
        33 Loop count

   NUM_COL CHAR_COL
---------- ------------------------------------------------------------
        34 Loop count
        35 Loop count
        36 Loop count
        37 Loop count
        38 Loop count
        39 Loop count
        40 Loop count
        41 Loop count
        42 Loop count
        43 Loop count
        44 Loop count

   NUM_COL CHAR_COL
---------- ------------------------------------------------------------
        45 Loop count
        46 Loop count
        47 Loop count
        48 Loop count
        49 Loop count
        50 Loop count
           Done!

51 rows selected.

SQL>
SQL> drop table MyTable;

Table dropped.

   
    
  
Related examples in the same category
1. GOTO statement.
2. Example of a proper GOTO statement
3. GOTO a Label
4. This script demonstrates GOTO
5. Use sequential control with the GOTO statement and a block label
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.