EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials Oracle Tutorial Oracle Procedures
Secondary Sidebar
Oracle Tutorial
  • Advanced
    • Timestamp to Date in Oracle
    • Oracle Golden Gate
    • Oracle Virtual Machine
    • Oracle Describe Table
    • Oracle Clauses
    • Oracle Having Clause
    • Oracle?Primavera
    • Oracle FOREIGN Key
    • PIVOT in Oracle
    • Oracle Alter Table
    • Oracle Queries
    • Oracle Views
    • Oracle Window Functions
    • Oracle String Functions
    • Oracle Date Functions
    • Oracle Analytic Functions
    • Oracle Aggregate Functions
    • Select in Oracle
    • INSERT in Oracle
    • DISTINCT in Oracle
    • Function in Oracle
    • Oracle GROUP_CONCAT
    • Oracle INSTR()
    • Oracle CONVERT
    • Oracle LENGTH()
    • Oracle EXISTS
    • Oracle REPLACE()
    • Oracle MERGE
    • Oracle LEAD()
    • Oracle EXTRACT()
    • Oracle LISTAGG()
    • Oracle SYS_CONTEXT()
    • Oracle COALESCE
    • Oracle NVL()
    • Oracle SYSDATE()
    • Oracle?Date Format
    • Oracle SYS_GUID()
    • Oracle WILDCARDS
    • Oracle Synonyms
    • Oracle Subquery
    • BETWEEN in Oracle
    • FETCH in Oracle
    • Oracle Index
    • Oracle Function-based Index
    • Oracle UNIQUE Index
    • Oracle Bitmap Index
    • Oracle Column
    • Oracle Triggers
    • Oracle Procedures
    • Sample Database for Oracle
    • Oracle LIKE Operator
    • ORDER BY in Oracle
    • Oracle ORDER BY DESC
    • GROUP BY in Oracle
    • Oracle GROUP BY HAVING
    • Oracle Aliases
    • Table in Oracle
    • Oracle Temporary Table
    • Oracle? Table Partition
    • Oracle rename table
    • Oracle CTE
    • Cursor in Oracle
    • Oracle LOCK TABLE
    • Oracle Tablespace
    • Oracle CARDINALITY
    • Oracle REGEXP
    • Oracle REGEXP_REPLACE
    • Oracle to_date
    • JSON in Oracle
    • Oracle COMMIT
    • Oracle GRANT
    • Oracle MD5
    • Oracle ROLLBACK
    • Oracle Users
    • Oracle TIMESTAMP
    • IF THEN ELSE in Oracle
    • Oracle While Loop
    • Oracle Clone Database
    • Oracle Backup Database
    • Oracle? XML
    • Oracle XMLAGG
    • Oracle XMLTABLE
    • Oracle Performance Tuning
    • Oracle B Tree Index
    • Oracle fusion
    • Oracle ebs
    • Oracle GRC
    • Oracle ERP
    • Oracle ASM
    • Oracle Cloud
    • Oracle HCM Cloud
    • Oracle Integration Cloud
    • Oracle Jinitiator
    • Oracle pathfinder
    • Oracle VirtualBox
    • Oracle Weblogic Server
    • Oracle decode
    • Oracle Exadata
    • Oracle ZFS
    • Oracle? utilities
    • JDBC Driver for Oracle
    • Oracle? DBA Versions
    • Oracle DBA Salary
  • Basic
    • Oracle Marketing Cloud
    • What is Oracle?
    • Career in Oracle
    • How to Install Oracle
    • Oracle Versions
    • What Is Oracle Database
    • Oracle Data Warehousing
    • Oracle Warehouse Builder
    • Career In Oracle Database Administrator
    • Career In Oracle DBA
    • What is Oracle RAC
    • Oracle DBA
    • Oracle? Vanderbilt
    • What is RMAN Oracle
    • Oracle Database Administration
    • Oracle Operators
    • Oracle Constraints
    • Oracle number
    • Oracle Data Types
    • Oracle UNIQUE Constraint
    • Oracle Check Constraint
  • Joins
    • Joins in Oracle
    • Inner Join in Oracle
    • Oracle Cross Join
    • Left Join in Oracle
    • OUTER Join in Oracle
    • Oracle Full Outer Join
    • Natural Join in Oracle
    • Oracle Self Join
    • Oracle hash join
    • Oracle? Update with Join
  • Oracle SET Operators
    • UNION in Oracle
    • Oracle UNION ALL
    • INTERSECT in Oracle
    • MINUS in Oracle
  • Interview Questions
    • Oracle Interview Questions
    • Oracle Apps Interview Questions
    • Oracle Apps Technical Interview Questions
    • Oracle Database Interview Questions
    • Oracle Forms Interview Questions
    • Oracle PL/SQL Interview Questions
    • Oracle RAC Interview Questions
    • Oracle SOA Interview Questions

Related Courses

Oracle Course Training

Oracle DBA Certification Course

MongoDB Certification Training

Oracle Procedures

By Priya PedamkarPriya Pedamkar

Oracle Procedures

Introduction to Oracle Procedures

Procedures in Oracle can be called as subprograms, that are stored in the database used to execute specific operations on the contents of the database or tables. Like any other program, procedures should also have a few mandatory parameters so as to call and execute the procedure successfully, such as, procedure name, Arguments like IN, OUT or IN OUT for passing the values when the procedure is called, a declaration section for declaring the variables and the datatypes, and finally the main section that is to be executed.

Syntax for Creating a Procedure:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

CREATE OR REPLACE procedure_name ([optional argument])
IS
[declaration section] BEGIN
[executable section] END

Parameters of Oracle Procedures:

The description of the different parameters used in the syntax are provided below:

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (85,992 ratings)

1. procedure_name: The name of the procedure which is getting created.

2. Optional Argument: It refers to the argument that will get passed when the procedure is called. There are three types of arguments:

  • IN: It is a default parameter. It is used to pass a value to the parameter. We can pass a constant, literal or expression as an IN parameter. Their values cannot be changed inside a subprogram.
  • OUT: It is used to return a value to the caller of the procedure. We can update the value of the OUT parameter inside the procedure.
  • IN OUT: It passes an initial value to the procedure and returns an updated value to the caller. An INOUT parameter is typically a string buffer that is read inside the program and then updated.

3. Declaration Section: It is used to declare variables and their data types.

4. Executable Section: This section consists of statements that are actually executed to retrieve or update values in the database.

Syntax for Calling a Procedure:

BEGIN
Procedure_name(arguments)
END

Here we are giving the name of the stored procedure along with arguments if any between BEGIN and END to call the procedure. So, now we are going to see how the actual procedure works in oracle.

How Do Oracle Procedures Work?

So, since we have already gone through the syntax of procedures. Let us now discuss actually how procedures get executed. Procedures, as discussed above, are a named subprogram in PL/SQL which is generally used when we want to have reusability. So one important point to keep in mind since procedures is a named subprogram is stored in the schema level in the database. So, it is stored in the database until we drop the procedure.

A procedure consists of three parts. The first part is declarative, the second one is executable and the third one is an exception. The control first goes to the declarative part contains the declaration of cursors, types, constants, expressions and also nested subprograms. The declared items are local to the procedure and ceased to exist as soon as the procedure completes execution.

After that, we have the executable part in which we actually manipulate the data by executing the statements. If we get any error while execution than we will have an exception handling section where the exception is handled during run-time. One point to keep in mind is that both the declarative and Exception Handling section is optional. It is a good practiced to handle run-time exceptions in procedures.

There are two types of parameters in Procedures formal parameters and actual parameters. Formal Parameters are variables declared in the header whereas actual parameters are the values that we pass to the subprogram when we actually invoke it.

Now we will look or go through some examples to check how to create and execute procedures that we help us to get a better understanding.

Examples of Oracle Procedures

Below are examples of oracle procedures:

1. Creating a Procedure to Print the Input Name

In this example, we are creating a procedure in which we take a name as input and then print that name with a message as output. Let us look at the example below:

Query for Creating a Procedure:

CREATE OR REPLACE PROCEDURE first_procedure (p_myname IN VARCHAR2)
IS
BEGIN
dbms_output.put_line ('Hi! my name is' ||p_myname);
END;

Now let us go through the code the first line says us the name of the procedure and what type of parameter it is taking as an input. In our case, the name is ‘first_procedure’ and parameter ‘p_myname’ of type IN.

In the executable section which is present after the BEGIN keyword, we are printing the message by concatenating the input name. Now let us run the above query in SQL developer and the below screenshot shows us the same.

Output:

Oracle Procedures 1-1

2. Executing a Procedure to Print the Input Name

In this example, we are executing a procedure. Let us look at the example below:

Query for Executing a Procedure:

SET SERVEROUTPUT ON
BEGIN
first_procedure('Nilanjan');
END;

In this above query, we are executing the above-created procedure bypassing the input parameter in the parenthesis. One important point to note is that if we are using SQL developer we have to set the server output ON first. The same is not required in SQL*Plus.

Now let us execute the query in SQL developer and we get the below output.

Output:

Oracle Procedures 1-2

As you can see in executing the procedure it prints the name along with a message.

3. Dropping a Procedure

In this example, we are dropping a procedure. Let us look at the example below:

Query for Dropping a Procedure:

A procedure remains in the database until we drop it from the database. So, in case we want to remove a procedure from the database we will have to use DROP. The below query shows how to drop a procedure from the database.

DROP PROCEDURE first_procedure;

In the above query, we are just providing the procedure name with the DROP keyword. Once the procedure is dropped it is removed from the database and hence we cannot execute it. Let us run the above query in SQL developer and we can see the output of the above query in the below screenshot.

Output:

Dropping

Conclusion

In this article, we have learned about the procedures in ORACLE and how to use them. The article also discusses the syntax and their parameters. We also saw how to create and delete procedures in oracle database through an example.

Recommended Articles

This is a guide to Oracle Procedures. Here we discuss the Parameters of Oracle Procedures along with the Working and Examples. You may also look at the following articles to learn more –

  1. Top 8 Components of Oracle Warehouse Builder
  2. Oracle PL/SQL Interview Questions
  3. 10 Different Types of Joins in Oracle
  4. How to use DISTINCT in Oracle?
  5. Complete Guide to Relational Database
  6. Oracle Operators | Top 7 Operators
  7. PostgreSQL Procedures | Working and Examples
Popular Course in this category
Oracle Training (14 Courses, 8+ Projects)
  14 Online Courses |  8 Hands-on Projects |  120+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Oracle DBA Database Management System Training (2 Courses)4.9
All in One Financial Analyst Bundle- 250+ Courses, 40+ Projects4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more