Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

Oracle 9i Procedures and Functions

By Exforsys | on March 13, 2005 |
Oracle 9i

This tutorial covers Developing Procedures and Functions, Creating a Procedure, Executing a Procedure, Creating a Function, Executing a Function, Passing Parameters – IN Parameters, OUT Parameters, IN OUT Parameters, Purity of a User-Defined Function and Positional and Named Notations.

Oracle 9i : Procedures and Functions

PL/SQL subprograms

A subprogram is a named block of PL/SQL. There are two types of subprograms in PL/SQL namely Procedures and Functions. Every subprogram will have a declarative part, an executable part or body, and an exception handling part, which is optional.

Declarative part contains variable declarations. Body of a subprogram contains executable statements of SQL and PL/SQL. Statements to handle exceptions are written in exception part.

When client executes a procedure are function, the processing is done in the server. This reduces network traffic. The subprograms are compiled and stored in the Oracle database as stored programs and can be invoked whenever required. As they are stored in compiled form when called they only need to be executed. Hence they save time needed for compilation.

Subprograms provide the following advantages 

  1. They allow you to write PL/SQL program that meet our need
  2. They allow you to break the program into manageable modules. 
  3. They provide reusability and maintainability for the code.

Procedures

Procedure is a subprogram used to perform a specific action. A procedure contains two parts specification and the body. Procedure specification begins with CREATE and ends with procedure name or parameters list. Procedures that do not take parameters are written without a parenthesis. The body of the procedure starts after the keyword IS or AS and ends with keyword END.

In the above given syntax things enclosed in between angular brackets (“< > “) are user defined and those enclosed in square brackets (“[ ]”) are optional.

OR REPLACE is used to overwrite the procedure with the same name if there is any.

AUTHID clause is used to decide whether the procedure should execute with invoker (current-user or person who executes it) or with definer (owner or person created) rights

Example

CREATE PROCEDURE MyProc (ENO NUMBER)
AUTHID DEFINER AS
BEGIN
DELETE FROM EMP
WHERE EMPNO= ENO;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE(‘No employee with this number’);
END;

Let us assume that above procedure is created in SCOTT schema (SCOTT user area) and say is executed by user SEENU. It will delete rows from the table EMP owned by SCOTT, but not from the EMP owned by SEENU. It is possible to use a procedure owned by one user on tables owned by other users. It is possible by setting invoker-rights

AUTHID CURRENT_USER

PRAGMA AUTONOMOUS_TRANSACTION is used to instruct the compiler to treat the procedure as autonomous. i.e. commit or rollback the changes made by the procedure.

Parameter Modes

Parameters are used to pass the values to the procedure being called. There are 3 modes to be used with parameters based on their usage. IN, OUT, and IN OUT.

IN mode parameter used to pass the values to the called procedure. Inside the program IN parameter acts like a constant. i.e it cannot be modified.

OUT mode parameter allows you to return the value from the procedure. Inside Procedure the OUT parameter acts like an uninitialized variable. Therefore its value cannot be assigned to another variable.

IN OUT mode parameter allows you to both pass to and return values from the subprogram. Default mode of an argument is IN.

POSITIONAL vs. NOTATIONAL parameters

A procedure can be communicated by passing parameters to it. The parameters passed to a procedure may follow either positional notation or named notation.

Example

If a procedure is defined as GROSS (ESAL NUMBER, ECOM NUMBER)
If we call this procedure as GROSS (ESA, ECO) then parameters used are called positional parameters. For Notational Parameters we use the following syntax
GROSS (ECOM => ECO, ESAL => ESA)

A procedure can also be executed by invoking it as an executable statement as shown below.

BEGIN
PROC1; — PROC1 is name of the procedure.
END;
/

Functions:

A function is a PL/SQL subprogram, which is used to compute a value. Function is same like a procedure except for the difference that it have RETURN clause.

Syntax for Function

Examples

Function without arguments

Function with arguments. Different ways of executing the function.

Privileges for creation and execution of procedures

To create a procedure in current user schema we use the syntax

CREATE OR REPLACE PROCEDURE (<argslist) IS
——-
——-

To create procedure in any schema we use

CREATE OR REPLACE ANY PROCEDURE (<argslist) IS
——-
——-

To grant EXECUTE privilege to some user on a procedure we write
GRANT EXECUTE ON <procedure-name> TO <user-name>

SQL>SELECT * FROM USER_PROCEDURES;
Lists all the procedures, functions in current user.

SQL>SELECT * FROM USER_PROCEDURES;
Lists all the procedures, functions in all users.

SQL>DROP PROCEDURE <procedure-name> ;
Drops or Removes a procedure from database.

SQL>DROP FUNCTION <function-name> ; 
Drops or Removes a function from database.

« « SQL Server 2000: Using System and Extended Stored Procedures
MSAS : Microsoft Data Warehousing Overview » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 391 Followers
  • Popular
  • Recent
  • Oracle 9i Utilities

    April 30, 2005 - 0 Comment
  • Oracle 9i Tables and Constraints

    February 2, 2005 - 0 Comment
  • Introduction to Oracle 9i SQL, PLSQL, and SQL *Plus

    October 24, 2004 - 0 Comment
  • More Oracle 9i Database Objects

    February 14, 2005 - 0 Comment
  • Oracle 9i Software Installation, SQL, PLSQL and SQL *Plus References

    October 25, 2004 - 0 Comment
  • Building PL/SQL Blocks in Oracle 9i

    February 16, 2005 - 0 Comment
  • Oracle 9i PL/SQL Control Structures

    February 26, 2005 - 0 Comment
  • Oracle 9i Cursors

    February 27, 2005 - 0 Comment
  • Download example SQL Scripts used in Oracle 9i Tutorials

    March 3, 2005 - 0 Comment
  • Oracle 9i Exception Handling

    March 3, 2005 - 0 Comment
  • Oracle 9i Utilities

    April 30, 2005 - 0 Comment
  • Oracle 9i Packages

    April 7, 2005 - 0 Comment
  • Oracle 9i Database Triggers

    March 28, 2005 - 0 Comment
  • Oracle 9i PL/SQL Collections

    March 6, 2005 - 0 Comment
  • Oracle 9i Exception Handling

    March 3, 2005 - 0 Comment
  • Download example SQL Scripts used in Oracle 9i Tutorials

    March 3, 2005 - 0 Comment
  • Oracle 9i Cursors

    February 27, 2005 - 0 Comment
  • Oracle 9i PL/SQL Control Structures

    February 26, 2005 - 0 Comment
  • Building PL/SQL Blocks in Oracle 9i

    February 16, 2005 - 0 Comment
  • More Oracle 9i Database Objects

    February 14, 2005 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Oracle 9i Utilities
  • Oracle 9i Packages
  • Oracle 9i Database Triggers
  • Oracle 9i PL/SQL Collections
  • Oracle 9i Exception Handling

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT