The Wayback Machine - https://web.archive.org/web/20240930185257/https://www.geeksforgeeks.org/pl-sql-continue-statement/
Open In App

PL/SQL CONTINUE Statement

Last Updated : 04 Jan, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

PL/SQL is a block-structured language that enables developers to combine the power of SQL with procedural statements. All the statements of a block are passed to the Oracle engine all at once which increases processing speed and decreases the traffic.

CONTINUE Statement

In PL/SQL (Procedural Language/Structured Query Language), the CONTINUE statement is used within loops to skip the remaining statements within the loop for the current iteration and move on to the next iteration. The CONTINUE statement is commonly used in combination with conditional statements to control the flow of execution in loops.

Syntax:

CONTINUE;

Example:

DECLARE
   i NUMBER := 1;
BEGIN
   LOOP
      IF i = 3 THEN
         -- Skip the rest of the loop for i = 3
         i := i + 1;
         CONTINUE;
      END IF;

      -- Process other statements inside the loop
      DBMS_OUTPUT.PUT_LINE('Current Value of i: ' || i);

      i := i + 1;

      EXIT WHEN i > 5; -- Exit the loop when i exceeds 5
   END LOOP;
END;
/

When the above code is executed in SQL prompt, it produces the following output.

Output:

Current Value of i: 1
Current Value of i: 2
Current Value of i: 4
Current Value of i: 5

CONTINUE WHEN Statement

In PL/SQL, there isn’t a direct “CONTINUE WHEN” statement, but you can achieve similar functionality using conditional logic with IF statements. Here are multiple examples demonstrating how you can use conditional logic to control the flow within loops in PL/SQL.

Example 1: Using IF-CONTINUE to Skip Iterations

DECLARE
   i NUMBER := 1;
BEGIN
   FOR i IN 1..5 LOOP
      IF i = 4 THEN
         -- Skip the rest of the loop for i = 4
         CONTINUE;
      END IF;

      DBMS_OUTPUT.PUT_LINE('Current Value of i: ' || i);
   END LOOP;
END;
/

When the above code is executed in SQL prompt, it produces following output.

Output:

Current Value of i: 1
Current Value of i: 2
Current Value of i: 3
Current Value of i: 5

Example 2: Using IF-CONTINUE in a WHILE Loop

DECLARE
   i NUMBER := 1;
BEGIN
   WHILE i <= 5 LOOP
      IF i = 3 THEN
         -- Skip the rest of the loop for i = 3
         i := i + 1;
         CONTINUE;
      END IF;

      DBMS_OUTPUT.PUT_LINE('Current Value of i: ' || i);
      i := i + 1;
   END LOOP;
END;
/

When the above code is executed in SQL prompt, it produces the following output.

Output:

Current Value of i: 1
Current Value of i: 2
Current Value of i: 4
Current Value of i: 5

Example 3: Using IF-CONTINUE in a Nested Loop

DECLARE
   i NUMBER := 1;
   j NUMBER := 1;
BEGIN
   FOR i IN 1..3 LOOP
      FOR j IN 1..3 LOOP
         IF j = 2 THEN
            -- Skip the rest of the inner loop for j = 2
            CONTINUE;
         END IF;

         DBMS_OUTPUT.PUT_LINE('i: ' || i || ', j: ' || j);
      END LOOP;
   END LOOP;
END;
/

When the above code is executed in SQL prompt, it produces the following output.

Output:

i: 1, j: 1
i: 1, j: 3
i: 2, j: 1
i: 2, j: 3
i: 3, j: 1
i: 3, j: 3

In each example, the CONTINUE-like behavior is achieved using an IF statement to skip the remaining code for a specific condition. The loop then continues with the next iteration. These examples illustrate how conditional logic can be used to control the flow within loops in PL/SQL.

Advantages of PL/SQL CONTINUE Statement

  • Provides a way to skip some specific iterations.
  • Useful to skip the necessary processing in the loop.
  • The nesting levels can be reduced as we may want to skip the rest of the loops.
  • We can selectively skip certain iterations based on specific conditions.

Conclusion

CONTINUE statement terminates the current iteration of a loop within a PL/SQL code block, and moves to the next iteration of the loop. This statement can be embedded within a FOR LOOP , or WHILE statement, or a PL/SQL procedure, function.It provides a way to efficiently manage loop iterations by bypassing unnecessary code execution based on certain conditions.



Similar Reads

SELECT Statement in MariaDB
MariaDB uses SQL (Structured Query Language) and it is an open-source relational database management system (RDBMS) for managing and manipulating data. The SELECT statement is the most basic of all the SQL statements. It is essential to get data out of one or more database tables and display it. In this article, we will examine the syntax of the SE
3 min read
ORDER BY Statement in MariaDB
In MariaDB, the ORDER BY clause is an important component for organizing the result set of a query in a certain order. Being aware of the complexities of ORDER BY can significantly improve your capacity to get and evaluate data effectively, regardless of whether you're working with one or more columns, ascending or descending sorting, or both. This
3 min read
SQLite Replace Statement
SQLite is a database engine. It is a serverless architecture as it does not require any server to process queries. Since it is serverless, it is lightweight and preferable for small datasets. It is used to develop embedded software. It is cross-platform and available for various Operating systems such as Linux, macOS, Windows, Android, and so on. R
3 min read
SQLite Update Statement
SQLite is a database engine. It is a software that allows users to interact with relational databases, Basically, it is a serverless database which means it does not require any server to process queries. With the help of SQLite, we can develop embedded software without any configurations. SQLite is preferable for small datasets. Update StatementSo
3 min read
MariaDB INSERT Statement
MariaDB is a famous open-source relational database management system. It is renowned for its performance, scalability, and robust functions. One essential thing about operating with databases is the ability to insert information, and the INSERT statement plays a crucial role in this technique. In this article, we can explore the MariaDB INSERT dec
3 min read
SQL Server MERGE Statement
MERGE is a powerful SQL statement that allows you to perform INSERT/UPDATE/DELETE operations depending on the conditions you specify. It makes it easy to synchronize data between source and destination tables. This makes it efficient to handle data changes in one single statement. MERGE makes it easier to manage complex operations such as data ware
6 min read
PL/SQL GOTO Statement
PL/SQL also known as Procedural Language/Structured Query Language, PL/SQL is a powerful programming language used in Oracle databases to do interaction with data. One of its features is the GOTO statement, which helps control how a program flows by allowing it to jump to specific statements within the same part of the program. What is the GOTO Sta
5 min read
PL/SQL NULL Statement
PL/SQL, the Procedural Language/Structured Query Language, is a database programming language utilized for database management in Oracle. Within this language, the Null statement plays a crucial role in enhancing code readability and functionality. This article aims to delve into the significance of the Null statement in PL/SQL, exploring its vario
5 min read
MariaDB UPDATE Statement
MariaDB uses SQL (Structured Query Language) and it is an open-source relational database management system (RDBMS) for managing and manipulating data. MariaDB is known for its high performance, even on large datasets. This makes it a good choice for applications that require fast data access. MariaDB can be used to handle large amounts of data wit
6 min read
PL/SQL CASE Statement
PL/SQL stands for Procedural Language Extension to the Structured Query Language and it is designed specifically for Oracle databases it extends Structured Query Language (SQL) capabilities by allowing the creation of stored procedures, functions, and triggers. It is a block-structured language that combines SQL with the procedural features of prog
4 min read
SQL INSERT INTO SELECT Statement
In SQL, the INSERT INTO statement is used to add or insert records to the specified table. We can use this statement to add data directly to the table. We use the VALUES keyword along with the INSERT INTO statement. VALUES keyword is accompanied by column names in a specific order in which we want to insert values in them. SELECT statement is used
5 min read
Nested Select Statement in MySQL
The relational databases, the ability to retrieve and manipulate data with precision is a cornerstone of effective database management. MySQL, a popular relational database management system, provides a powerful tool called the Nested SELECT statement that empowers developers to perform complex and versatile data queries. So, In this article we wil
5 min read
SQL Server SELECT INTO Statement
SQL Server is a relational database management system. SQL Server offers robust security features to protect data integrity and confidentiality. It includes authentication, authorization, encryption, and various mechanisms to secure the database environment. It is designed to scale from small applications to large, enterprise-level databases. It pr
6 min read
What is Nested Select Statement in PL/SQL?
PL/SQL is a Procedural Language/Structured Query Language and it enables users to write procedural logic directly within the database, including procedures, functions, triggers, and packages. In this article, we will understand Nested select statements in PL/SQL along with the examples and so on. Understanding Nested Select Statement in PL/SQLThe n
4 min read
What is the CASE statement in SQL Server with or condition?
In SQL Server, the CASE statement cannot directly support the use of logical operators like OR with its structure. Instead of CASE it operates based on the evaluation of multiple conditions using the WHEN keyword followed by specific conditions. In this article, we will learn about the OR is not supported with CASE Statement in SQL Server with a de
4 min read
What is Nested Select Statement in SQL Server
SQL Server is a powerful relational database management system. Sql Server is very good with its robustness and scalability. SQL Server operates as a client-server structure, imparting centralized management and scalability for huge-scale applications and enterprise-stage solutions. It offers advanced features which include excessive availability,
3 min read
What is Nested Select Statement in PostgreSQL?
Nested select statements, also known as subqueries which is a fundamental concept in PostgreSQL and play an important role in data retrieval and manipulation. In PostgreSQL, a powerful relational database management system, the nested select statements allow for complex queries by nesting one query within another. In this article, We will explore t
4 min read
How to Call a Stored Procedure Using Select Statement in MySQL?
Stored procedures in MySQL are powerful tools for encapsulating SQL logic and enabling reusability. However, executing stored procedures via SELECT statements can provide additional flexibility, especially when integrating their results directly into queries. This article explores various methods of calling stored procedures using SELECT statements
6 min read
What is Nested Select Statement in MariaDB
Nested select statements, normally named subqueries, represent an advanced feature for MariaDB which enables more efficient and thorough querying of the data. Therefore, the nesting of a SELECT statement within another allows us to perform operations and filtering that could be hardly possible with only one query. In this article, we'll explore the
4 min read
PL/SQL Statement level Triggers
Statement-level triggers in Oracle databases execute actions for each transaction, responding to various database events like DML and DDL statements, system events, and user interactions. They act as programmed responses to specific table events, enhancing database management and automation. Stored as named PL/SQL blocks, triggers execute automatic
5 min read
SQL CREATE VIEW Statement
The SQL CREATE VIEW statement is a very powerful feature in RDBMSs that allows users to create virtual tables based on the result set of a SQL query. Unlike regular tables, these views do not store data themselves rather they provide a way of dynamically retrieving and presenting data from one or many underlying tables. Views help simplify complex
4 min read
PL/SQL INSERT Statement
The PL/SQL INSERT statement is vital for adding new records to a database table. By specifying the table's name and providing values for its columns, users can populate their database with essential information. This functionality enables efficient data entry and ensures the completeness of datasets, facilitating various database operations and ana
3 min read
How to Combine LIKE and IN in SQL Statement
Combining 'LIKE' and 'IN' operators in SQL can greatly enhance users' ability to retrieve specific data from a database. By Learning how to use these operators together users can perform more complex queries and efficiently filter data based on multiple criteria, making queries more precise and targeted. This article explores how the LIKE and IN op
4 min read
MySQL - SHOW VARIABLES Statement
MySQL is an open-source Relational Database Management System that stores data in the form of rows and tables and SQL is known as a programming language that is used to manipulate the data. We can perform many operations in an SQL server with the help of SQL programming language such as manipulating the data, retrieving the data, and storing the da
3 min read
PL/SQL CREATE TABLE Statement
PL/SQL CREATE TABLE statement is a fundamental aspect of database design and allows users to define the structure of new tables, including columns, data types and constraints. This statement is crucial in organizing data effectively within a database and providing a blueprint for how data should be structured. In this article, we will explore the s
4 min read
How to Use PL SQL Insert, Update, Delete And Select Statement?
PL/SQL is a powerful extension of SQL specifically designed for Oracle databases. It enables developers to create procedural logic and execute SQL commands within Oracle database environments. In this article, we will explore the usage of fundamental PL/SQL statements such as INSERT, UPDATE, DELETE and SELECT with he help of various examples which
6 min read
MySQL Create Database Statement
The MySQL CREATE DATABASE statement is used to create a new database. It allows you to specify the database name and optional settings, such as character set and collation, ensuring the database is ready for storing and managing data. In this article, we are going to learn how we can create databases in the MySQL database management system through
4 min read
SQL UPDATE Statement
SQL UPDATE Statement modifies the existing data from the table. UPDATE Statement in SQL The UPDATE statement in SQL is used to update the data of an existing table in the database. We can update single columns as well as multiple columns using the UPDATE statement as per our requirement. In a very simple way, we can say that SQL commands(UPDATE and
3 min read
MySQL UPDATE Statement
MySQL is a popular relational database management system used in applications ranging from small projects to large enterprises. The UPDATE statement in MySQL is essential for modifying existing data in a table. It's commonly used to correct errors, update values, and make other necessary changes. This article explores the structure and use cases of
5 min read
MySQL DELETE Statement
In DBMS, CRUD operations (Create, Read, Update, Delete) are essential for effective data management. The Delete operation is crucial for removing data from a database. This guide covers the MySQL DELETE statement, exploring its syntax and providing examples. Understanding how DELETE works helps ensure accurate and safe data removal, preventing acci
6 min read