---
description: In PL/SQL, the code is not executed in single line format, but it is always executed by grouping the code into a single element called Blocks. In this tutorial, you are going to learn about these blocks.
title: PL/SQL Block: Structure, Syntax &#038; Anonymous Example
image: https://www.guru99.com/images/plsql-block-structure-syntax.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

PL/SQL Block is the basic unit that groups PL/SQL and SQL instructions so they execute together rather than line by line. Every block has a declaration, execution, and exception-handling section, and blocks are either anonymous or named.

* 🧱 **Core Idea:** Code is grouped into a block that runs as a whole, mixing procedural logic with SQL.
* 📝 **Declaration Section:** Optional; declares variables, cursors, exceptions, and subprograms used in the block.
* ▶️ **Execution Section:** Mandatory; begins with BEGIN and holds at least one executable statement.
* 🛡️ **Exception Section:** Optional; begins with EXCEPTION and handles run-time errors.
* 🏷️ **Two Types:** Anonymous blocks are unnamed and run once; named blocks are stored as database objects.
* 🔁 **Named Blocks:** Procedures and functions are named blocks that can be called repeatedly.
* ⛔ **Terminator:** END closes the block, and a forward slash sends it to the compiler.

[ Read More ](javascript:void%280%29;) 

![PL/SQL Block Structure and Syntax](https://www.guru99.com/images/plsql-block-structure-syntax.png)

## What is a PL/SQL Block?

In PL/SQL, code is not executed in single-line format; it is always executed by grouping the code into a single element called a block. In this tutorial, you will learn about these blocks.

Blocks contain both PL/SQL and SQL instructions. All these instructions are executed as a whole rather than one instruction at a time.

## Block Structure

PL/SQL blocks have a pre-defined structure in which the code is grouped. Below are the different sections of a PL/SQL block:

1. Declaration section
2. Execution section
3. Exception-Handling section

The picture below illustrates the different PL/SQL block sections and their order.

[](https://www.guru99.com/images/PL-SQL/110215%5F0632%5FBlocksinPLS1.png)

### Declaration Section

This is the first section of a PL/SQL block, and it is optional. It is the section in which variables, cursors, exceptions, subprograms, pragma instructions, and collections needed in the block are declared. A few more characteristics of this part:

* This section is optional and can be skipped if no declarations are needed.
* It should be the first section in a PL/SQL block, if present.
* It starts with the keyword ‘DECLARE’ for triggers and anonymous blocks. For other subprograms this keyword is not present; instead, the part after the subprogram name marks the declaration section.
* It should always be followed by the execution section.

### Execution Section

The execution part is the main and mandatory part that actually executes the code written inside it. Since [PL/SQL](https://www.guru99.com/introduction-pl-sql.html) expects executable statements, this block cannot be empty and must have at least one valid executable line. A few more characteristics of this part:

* It can contain both PL/SQL code and SQL code.
* It can contain one or many blocks inside it as nested blocks.
* It starts with the keyword ‘BEGIN’.
* It should be followed either by ‘END’ or by the exception-handling section, if present.

### Exception-Handling Section

Exceptions are unavoidable errors that occur at run-time, and to handle them Oracle provides an exception-handling section in blocks. This section can also contain PL/SQL statements, and it is optional.

* This is the section where an exception raised in the execution block is handled.
* It is the last part of the PL/SQL block.
* Control from this section can never return to the execution block.
* It starts with the keyword ‘EXCEPTION’.
* It should always be followed by the keyword ‘END’.

The keyword ‘END’ marks the end of the PL/SQL block.

## PL/SQL Block Syntax

Below is the syntax of the PL/SQL block structure.

[](https://www.guru99.com/images/PL-SQL/110215%5F0632%5FBlocksinPLS2.png)

DECLARE --optional
<declarations>

BEGIN --mandatory
<executable statements. At least one executable statement is mandatory>

EXCEPTION --optional
<exception handles>

END; --mandatory
/

**Note:** A block should always be followed by ‘/’, which sends information to the compiler about the end of the block.

### RELATED ARTICLES

* [Oracle PL/SQL Collections: Varrays, Nested & Index by Tables ](https://www.guru99.com/complex-data-types-pl-sql.html "Oracle PL/SQL Collections: Varrays, Nested & Index by Tables")
* [PL/SQL Acceptable Identifiers, Variable & Naming Conventions ](https://www.guru99.com/pl-sql-identifiers.html "PL/SQL Acceptable Identifiers, Variable & Naming Conventions")
* [Oracle PL/SQL BULK COLLECT: FORALL Example ](https://www.guru99.com/pl-sql-bulk-collect.html "Oracle PL/SQL BULK COLLECT: FORALL Example")
* [Autonomous Transaction in Oracle PL/SQL ](https://www.guru99.com/pl-sql-tcl-statements.html "Autonomous Transaction in Oracle PL/SQL")

## Types of PL/SQL Block

PL/SQL blocks are mainly of two types:

1. Anonymous blocks
2. Named blocks

The two are compared at a glance below before each is described.

| Aspect             | Anonymous Block   | Named Block       |
| ------------------ | ----------------- | ----------------- |
| Has a name         | No                | Yes               |
| Stored in database | No                | Yes, as an object |
| Starts with        | DECLARE or BEGIN  | CREATE            |
| Reusable           | Same session only | Callable any time |

### Anonymous Blocks

Anonymous blocks are PL/SQL blocks that do not have any name assigned to them. They need to be created and used in the same session because they are not stored on the server as database objects.

Since they are not stored in the database, they need no separate compilation step. They are written and executed directly, and compilation and execution happen in a single process. A few more characteristics:

* These blocks have no reference name.
* They start with the keyword ‘DECLARE’ or ‘BEGIN’.
* Because they have no reference name, they cannot be stored for later use and must be created and executed in the same session.
* They can call other named blocks, but a call to an anonymous block is not possible, as it has no reference.
* They can contain a nested block that is named or anonymous, and they can also be nested inside any block.
* They can have all three sections, of which the execution section is mandatory and the other two are optional.

### Named Blocks

Named blocks have a specific and unique name. They are stored as database objects on the server, so they can be referred to or used as long as they are present. The compilation process for named blocks happens separately when they are created as database objects. A few more characteristics:

* These blocks can be called from other blocks.
* The block structure is the same as an anonymous block, except that it never starts with ‘DECLARE’. Instead, it starts with ‘CREATE’, which instructs the compiler to create it as a database object.
* These blocks can be nested within other blocks and can also contain nested blocks.
* Named blocks are basically of two types:
1. Procedure
2. Function

You can learn more about these named blocks in the guide to [procedures and functions](https://www.guru99.com/subprograms-procedures-functions-pl-sql.html).

## FAQs

▶️ Which section of a PL/SQL block is mandatory?

Only the execution section, which begins with BEGIN and ends with END. The declaration and exception-handling sections are optional and can be omitted if they are not needed.

🏷️ What is the difference between an anonymous and a named block?

An anonymous block has no name, is not stored, and runs in the same session. A named block, such as a procedure or function, is stored as a database object and can be called repeatedly.

⛔ Why is a forward slash needed after a block?

In tools like SQL\*Plus, the slash on its own line tells the compiler the block is complete and should be run. Without it, the tool keeps waiting for more input.

🤖 Can AI convert an anonymous block into a stored procedure?

Yes. AI can wrap the logic in a CREATE PROCEDURE header, add parameters, and move declarations into place. Test the result, since a stored version may need explicit parameter modes and error handling.

🛡️ Can a block have exception handling without a declaration section?

Yes. The declaration and exception sections are independent options. A block can begin at BEGIN, skip declarations, and still include an EXCEPTION section before END to catch run-time errors.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/plsql-block-structure-syntax.png","url":"https://www.guru99.com/images/plsql-block-structure-syntax.png","width":"700","height":"250","caption":"PL/SQL Block Structure &amp; Syntax","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/blocks-pl-sql.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/pl-sql","name":"PL-SQL"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/blocks-pl-sql.html","name":"PL/SQL Block: Structure, Syntax &#038; Anonymous Example"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/blocks-pl-sql.html#webpage","url":"https://www.guru99.com/blocks-pl-sql.html","name":"PL/SQL Block: Structure, Syntax &#038; Anonymous Example","dateModified":"2026-07-22T16:18:59+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/plsql-block-structure-syntax.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/blocks-pl-sql.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/fiona","name":"Fiona Brown","description":"I'm Fiona brown, a Full Stack Developer with over a decade of experience, sharing practical guides on robust and scalable application development.","url":"https://www.guru99.com/author/fiona","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/fiona-brown-author.png","url":"https://www.guru99.com/images/fiona-brown-author.png","caption":"Fiona Brown","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"PL-SQL","headline":"PL/SQL Block: Structure, Syntax &#038; Anonymous Example","description":"In PL/SQL, the code is not executed in single line format, but it is always executed by grouping the code into a single element called Blocks. In this tutorial, you are going to learn about these blocks.","keywords":"pl-sql","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/fiona","name":"Fiona Brown"},"dateModified":"2026-07-22T16:18:59+05:30","image":{"@id":"https://www.guru99.com/images/plsql-block-structure-syntax.png"},"copyrightYear":"2026","name":"PL/SQL Block: Structure, Syntax &#038; Anonymous Example","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Which section of a PL/SQL block is mandatory?","acceptedAnswer":{"@type":"Answer","text":"Only the execution section, which begins with BEGIN and ends with END. The declaration and exception-handling sections are optional and can be omitted if they are not needed."}},{"@type":"Question","name":"What is the difference between an anonymous and a named block?","acceptedAnswer":{"@type":"Answer","text":"An anonymous block has no name, is not stored, and runs in the same session. A named block, such as a procedure or function, is stored as a database object and can be called repeatedly."}},{"@type":"Question","name":"Why is a forward slash needed after a block?","acceptedAnswer":{"@type":"Answer","text":"In tools like SQL*Plus, the slash on its own line tells the compiler the block is complete and should be run. Without it, the tool keeps waiting for more input."}},{"@type":"Question","name":"Can AI convert an anonymous block into a stored procedure?","acceptedAnswer":{"@type":"Answer","text":"Yes. AI can wrap the logic in a CREATE PROCEDURE header, add parameters, and move declarations into place. Test the result, since a stored version may need explicit parameter modes and error handling."}},{"@type":"Question","name":"Can a block have exception handling without a declaration section?","acceptedAnswer":{"@type":"Answer","text":"Yes. The declaration and exception sections are independent options. A block can begin at BEGIN, skip declarations, and still include an EXCEPTION section before END to catch run-time errors."}}]}],"@id":"https://www.guru99.com/blocks-pl-sql.html#schema-1148876","isPartOf":{"@id":"https://www.guru99.com/blocks-pl-sql.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/blocks-pl-sql.html#webpage"}}]}
```
