Basic Query in PL/SQL procedure
Last Updated :
26 Aug, 2024
PL/SQL (Procedural Language/Structured Query Language) is a powerful extension to SQL, designed to combine the robustness of SQL with procedural constructs like loops, conditions, and more. It plays a crucial role in writing complex database interactions in Oracle databases. This article will cover an overview of PL/SQL, basic query operations, and an in-depth look at parameter modes in PL/SQL subprograms.
What is PL/SQL?
PL/SQL Stands for procedural language extension to SQL. In a procedure, the role of the subprogram is to perform a particular task and it is a unit module of a program. It combined to form larger programs. A subprogram can be involved by another program which is called the calling program. PL/SQL provides a block structure of executable unit code. It provides procedural constructs, for example, in control structure includes loops, conditional statements, and variable, constant, and data type.
Key Features of PL/SQL
- It can be created at the schema level, inside a package, and inside a PL /SQL block.
- The schema-level subprogram is a standalone subprogram. It is created with the CREATE PROCEDURE statement. In the subprogram, it is stored in the database and can be deleted with the DROP PROCEDURE statement.
- It is stored in the database and the package is deleted with the DROP PACKAGE statement.
- PL/SQL provides to kind of subprogram function and procedure.
Function and procedure in PL /SQL
Let's understand the meaning of function and procedure in PL/SQL:
- Function:
- A function is designed to return a single value.
- They are often used when you need to compute a value and use it elsewhere in your application.
- Functions must return a value using the 'RETURN' statement.
- Procedure:
- Procedures perform a specific action but are not required to return a value.
- They are versatile and can include multiple operations such as inserting, updating, or deleting records in a database.
Creating Procedure in PL/SQL
The 'CREATE PROCEDURE' statement is used to define a procedure. You can also use 'OR REPLACE' to modify an existing procedure.
Here, we will discuss, how you can create the procedure using PL/SQL query as follows.
Syntax:
CREATE [ OR REPLACE ] PROCEDURE procedure_name
[( Parameter [ parameter ] ) ]
IS
[ declaration_section ]
BEGIN
executable_section
[ EXCEPTION
exception_section]
END [ procedure_name];
Removing procedure in PL/SQL
Once created, a procedure can be removed from the database using the DROP PROCEDURE statement.
Syntax:
DROP PROCEDURE procedure_name;
Example:
DROP PROCEDURE Update course;
Parameter modes in PL/ SQL subprograms
Parameter modes define how values are passed to and from the subprogram. There are three parameter modes in PL/SQL:
1. IN Mode
It is read read-only a parameter. IN parameter act like a constant. And within called program or function, It can be referenced. The program cannot assign a new value to the IN parameter. Their value cannot be changed inside the subprogram.
2. OUT Mode
It is used for getting output from the subprograms. It is a read-write variable inside the subprograms. Their value can be changed inside the subprogram.
3. IN OUT Mode
To get the input and output from the subprogram then this IN-OUT can be used for getting the results. Their values can be changed inside the subprograms.
Conclusion
PL/SQL is a versatile and powerful extension to SQL, offering more control and flexibility in writing database programs. Understanding how to perform basic query operations and work with subprograms is fundamental to leveraging the full capabilities of Oracle databases. From creating and removing procedures to effectively using parameter modes, PL/SQL is a key skill for database developers aiming to build scalable, maintainable, and high-performance applications.
Similar Reads
Procedures in PL/SQL PL/SQL procedures are reusable code blocks that perform specific actions or logic within a database environment. They consist of two main components such as the procedure header which defines the procedure name & optional parameters and the procedure body which contains the executable statements
4 min read
How to Drop Procedure in SQL In SQL, stored procedures are used to encapsulate complex logic and queries. However, there may come a time when we need to remove or delete a stored procedure from a database. In this article, we will cover the various methods for dropping a stored procedure in SQL along with examples and explanati
3 min read
Reverse a string in PL/SQL Prerequisite - PL/SQL introduction In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Given a string, the task is to reverse a string using P
1 min read
SQL Concepts and Queries In this article, we will discuss the overview of SQL and will mainly focus on Concepts and Queries and will understand each with the help of examples. Let's discuss it one by one.Overview :SQL is a computer language that is used for storing, manipulating, and retrieving data in a structured format.
5 min read
Prime number in PL/SQL Prerequisite â PL/SQL introductionA prime number is a whole number greater than 1, which is only divisible by 1 and itself. First few prime numbers are : 2 3 5 7 11 13 17 19 23 â¦..In PL/SQL code groups of commands are arranged within a block. A block group-related declarations or statements. In decl
1 min read
PostgreSQL - Introduction to Stored Procedures PostgreSQL allows the users to extend the database functionality with the help of user-defined functions and stored procedures through various procedural language elements, which are often referred to as stored procedures.The store procedures define functions for creating triggers or custom aggregat
5 min read
How to SELECT FROM Stored Procedure in SQL Stored procedures are precompiled SQL queries stored in the database that encapsulate logic and can accept parameters, perform operations and return results. They are widely used in SQL for encapsulating reusable logic, improving performance and enhancing security. In this article, weâll explore how
4 min read
Blocks in PL/SQL In PL/SQL, All statements are classified into units that is called Blocks. PL/SQL blocks can include variables, SQL statements, loops, constants, conditional statements and exception handling. Blocks can also build a function or a procedure or a package. The Declaration section: Code block start wit
3 min read
Some Useful System Stored Procedures in SQL Some Useful System Stored Procedures in SQL. These procedures are built-in procedures and will help to extract the definition and dependencies of the existing user-defined stored procedures. sp_help : This will display the Stored procedure Name, Schema Name, created date, and Time or if there are an
2 min read
SQL Stored Procedures Stored procedures are precompiled SQL statements that are stored in the database and can be executed as a single unit. SQL Stored Procedures are a powerful feature in database management systems (DBMS) that allow developers to encapsulate SQL code and business logic. When executed, they can accept i
7 min read