Categories: PLSQL Tutorials

What is difference between anonymous block and subprogram?

In my previous articles i have given the idea about the anonymous block of PL SQL in detail. The PL SQL always uses the block structure. The every query statements are written in the block structure. You may always face the question in PL SQL that what exactly the difference between anonymous block and subprogram in detail. I would like to explain the difference between the anonymous block an subprogram in this article. But before going deep in to difference i would like to explain the basic program structure of PL SQL with real life examples. You can execute those programs on LiveSQL.oracle.com website by registering to oracle.

What you will find in this article?

  1. About PL SQL block structure
  2. About Subprograms in PL SQL
  3. What is difference between block and subprograms

About PL SQL block structure :

The PL SQL is nothing but Procedural language structured query language. I already explained that all the PL SQL statements are written in between Begin and end. It has a specified block structure.

PL SQL Block structure

I have given the PL SQL block structure in above diagram. The different sections in the PL SQL block is as follows :

  1. Declare Section : The declare section is first section to run any PL SQL block. This is optional section where you can define multiple variables,cursors and user defined exceptions as well.

Example : Declare i_count number(10);

2.Begin..End Section : This is non optional block structure in which you can write multiple SQL and PL SQL statements. The common mistake programmers made is they forget to write end.

3.Exception : The other section is exception section where user can manage the user defined exceptions as well as the system exceptions.

Example : You can manage the DIVIDE_BY_ZERO exception in exception section.

About Subprograms of PL SQL :

The subprograms are nothing but the reusable blocks which you can save and use those blocks in achieving the functionalities again and again. There are following PL SQL subprograms.

  1. Procedures or Stored Procedures :

The procedures are nothing but the subprograms in which you can add and save the related functionality.You can reuse the procedures and call the procedures whenever required.

Stored Procedures

Functions : The functions are basics building block which will return the value. The functions are also used in select statements or you can call the functions in other PL SQL blocks as well.The function will return at least one value.

Functions

What is difference between Anonymous block and Subprogram :

Anonymous BlockSubprograms
These are unnamed programming blocks to achieve the functionalities.These are named programming subprograms which can be reused.
We need to compile anonymous blocks again and again.We need to compile subprogram once.
It is not stored in databasesSubprograms are stored in databases.
The anonymous blocks cannot invoked by other applicationsYou can call the subprograms in other applications
The anonymous block do not return valueThe functions will always return the value
It cannot take parametersThe procedures and functions will take input and output parameters
Difference between anonymous block and subprogram

I hope you like this article on difference between anonymous block and subprogram. If you like this article or if you have any issues or concerns kindly comment in comments section.

Amit S

Oracle Consultant with vast experience in Oracle BI and PL/SQL Development. Amiet is the admin head of this website who contributes by preparing tutorials and articles related to database technologies. He is responsible to manage the content and front-end of the website.

Share
Published by
Amit S

Recent Posts

What is Production support Hierarchy in organization?

In this article i would like to provide information about production support organization structure or…

1 hour ago

What are roles and responsibilities for L3 Support Engineer?

In my previous article I have given roles for L1 and L2 support engineer with…

2 hours ago

What are roles and responsibilities of L2 Engineer?

I have started this new series of how to become application support engineer. This article…

4 hours ago

What are Roles and Responsibilities of L1 Support Engineer with real industry examples?

In this series we are starting with Roles and responsibilities of L1 support engineer .…

5 hours ago

The Essential Guide to Cryptocurrency Exchange Platform Development for Beginners and Beyond

Introduction Cryptocurrencies took the world by storm, setting up a new financial system and breaking…

12 months ago

Top 20 System Administrator Interview Questions and answers

In my previous article I have given Top 20 technical support interview questions with its…

1 year ago