Passing Parameters. 2 home back first prev next last What Will I Learn? List the types of parameter modes Create a procedure that passes parameters Identify.

Slides:



Advertisements
Similar presentations
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
Advertisements

Persistent State of Package Variables. 2 home back first prev next last What Will I Learn? Identify persistent states of package variables Control the.
Advanced Package Concepts. 2 home back first prev next last What Will I Learn? Write packages that use the overloading feature Write packages that use.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
1 Copyright © 2004, Oracle. All rights reserved. Creating Stored Procedures.
Creating Packages. 2 home back first prev next last What Will I Learn? Describe the reasons for using a package Describe the two components of a package:
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
2 Copyright © 2004, Oracle. All rights reserved. Creating Stored Functions.
Copyright © SUPINFO. All rights reserved Procedures and functions.
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
Copyright  Oracle Corporation, All rights reserved. 3 Creating Procedures.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 6 Functions.
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 6 Functions.
PL/SQLPL/SQL Oracle11g : PL/SQL Programming Chapter 6 Functions.
CPS120: Introduction to Computer Science Functions.
Chapter Eleven Classes and Objects Programming with Microsoft Visual Basic th Edition.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Trapping Oracle Server Exceptions. 2 home back first prev next last What Will I Learn? Describe and provide an example of an error defined by the Oracle.
Manipulating Data in PL/SQL. 2 home back first prev next last What Will I Learn? Construct and execute PL/SQL statements that manipulate data with DML.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
Recognizing PL/SQL Lexical Units. 2 home back first prev next last What Will I Learn? List and define the different types of lexical units available in.
Handling Exceptions. 2 home back first prev next last What Will I Learn? Describe several advantages of including exception handling code in PL/SQL Describe.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
Using Oracle-Supplied Packages. 2 home back first prev next last What Will I Learn? Describe two common uses for the DBMS_OUTPUT server-supplied package.
INSERT Statement. 2 home back first prev next last What Will I Learn? Give examples of why it is important to be able to alter the data in a database.
Programming with Microsoft Visual Basic 2012 Chapter 11: Classes and Objects.
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
JavaScript, Fourth Edition
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
1 Brief Version of Starting Out with C++, 4th Brief Edition Chapter 6 Functions.
Dynamic SQL. 2 home back first prev next last What Will I Learn? Recall the stages through which all SQL statements pass Describe the reasons for using.
CREATING STORED PROCEDURES AND FUNCTIONS. Objectives After completing this lecture, you should be able to do the following: Differentiate between anonymous.
Introduction to Explicit Cursors. 2 home back first prev next last What Will I Learn? Distinguish between an implicit and an explicit cursor Describe.
Cursor FOR Loops. 2 home back first prev next last What Will I Learn? List and explain the benefits of using cursor FOR loops Create PL/SQL code to declare.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
Retrieving Data in PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Recognize the SQL statements that can.
An Introduction to Programming with C++ Sixth Edition Chapter 10 Void Functions.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Brief Edition Chapter 6 Functions.
Using Functions in SQL Statements. 2 home back first prev next last What Will I Learn? List the advantages of user-defined functions in SQL statements.
VHDL Discussion Subprograms IAY 0600 Digital Systems Design Alexander Sudnitson Tallinn University of Technology 1.
Oracle10g Developer: PL/SQL Programming1 Objectives Named program units How to identify parameters The CREATE PROCEDURE statement Creating a procedure.
Creating Procedures. PL/SQL Program Construct Tools Constructs Anonymous Block Application procedures or functions Application packages Application Triggers.
Oracle9i Developer: PL/SQL Programming Chapter 5 Functions.
Lab 2 Writing PL/SQL Blocks CISB514 Advanced Database Systems.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Introduction to PL/SQL N. Dimililer. About PL/SQL –PL/SQL is an extension to SQL with design features of programming languages. –Data manipulation and.
Stored Procedures and Functions Pemrograman Basis Data MI2183.
STORED PROCEDURE & STORED FUNCTION Politeknik Telkom 2012.
6 Copyright © 2009, Oracle. All rights reserved. Using Dynamic SQL.
Chapter 9: Value-Returning Functions
Creating Stored Functions
Oracle11g: PL/SQL Programming Chapter 5 Procedures.
Creating Stored Procedures
3 Introduction to Classes and Objects.
Enumeration Type Data type: a set of values with a set of operations on them Enumeration type: a simple data type created by the programmer To define an.
Creating Stored Procedures and Functions
Java Primer 1: Types, Classes and Operators
Chapter 3: Using Methods, Classes, and Objects
The Selection Structure
Method.
Introduction to Procedures
Oracle Stored Procedures and Functions
Using the Set Operators
Database Management Systems 2
VHDL Discussion Subprograms
Creating Noninput Items
VHDL Discussion Subprograms
Peter Seibel Practical Common Lisp Peter Seibel
Prof. Arfaoui. COM390 Chapter 6
Presentation transcript:

Passing Parameters

2 home back first prev next last What Will I Learn? List the types of parameter modes Create a procedure that passes parameters Identify three methods for passing parameters Describe the DEFAULT option for parameters

3 home back first prev next last Why Learn It? To make procedures more flexible, it is important that varying data is either calculated or passed into a procedure by using input parameters. Calculated results can be returned to the caller of a procedure by using OUT or IN OUT parameters.

4 home back first prev next last Procedural Parameter Modes Parameter modes are specified in the formal parameter declaration, after the parameter name and before its data type. Parameter-passing modes: –An IN parameter (the default) provides values for a subprogram to process. –An OUT parameter returns a value to the caller. –An IN OUT parameter supplies an input value, which may be returned (output) as a modified value.

5 home back first prev next last The IN mode is the default if no mode is specified IN parameters can only be read within the procedure. They cannot be modified.

6 home back first prev next last Using OUT Parameters: Example

7 home back first prev next last Using the previous OUT example Create a procedure with OUT parameters to retrieve information about an employee. –The procedure accepts the value 178 for employee ID and retrieves the name and salary of the employee with ID 178 into the two OUT parameters. –The query_emp procedure has three formal parameters.  Two of them are OUT parameters that return values to the calling environment, shown in the code box at the bottom of the slide. Note –Make sure that the data type for the actual parameter variables used to retrieve values from OUT parameters has a size large enough to hold the data values being returned.

8 home back first prev next last Viewing OUT Parameters in Application Express Use PL/SQL variables that are displayed with calls to the DBMS_OUTPUT.PUT_LINE procedure.

9 home back first prev next last Using IN OUT Parameters: Example

10 home back first prev next last Using the previous IN OUT example Using an IN OUT parameter, you can pass a value into a procedure that can be updated within the procedure. The actual parameter value supplied from the calling environment can return as either of the following: –The original unchanged value –A new value that is set within the procedure  The example in the previous slide creates a procedure with an IN OUT parameter to accept a 10-character string containing digits for a phone number. The procedure returns the phone number formatted with parentheses around the first three characters and a hyphen after the sixth digit—for example, the phone string ‘ ’ is returned as ‘(800) ’.

11 home back first prev next last Calling the previous IN OUT example The following code creates an anonymous block which declares a_phone_no, assigns the unformatted phone number to it, and passes it as an actual parameter to the FORMAT_PHONE procedure. The procedure is executed and returns an updated string in the a_phone_no variable, which is then displayed.

12 home back first prev next last Summary of Parameter Modes The purpose of the default value: Caller may omit this parameter. But IN OUT parameter may be assigned a value in the procedure and can not be omitted.

13 home back first prev next last Syntax for Passing Parameters There are three ways of passing parameters from the calling environment: –Positional:  Lists the actual parameters in the same order as the formal parameters –Named:  Lists the actual parameters in arbitrary order and uses the association operator ( ‘=>' which is an equal and an arrow together) to associate a named formal parameter with its actual parameter –Combination:  Lists some of the actual parameters as positional (no special operator) and some as named (with the => operator).

14 home back first prev next last Parameter Passing: Examples

15 home back first prev next last Parameter Passing Will the following call execute successfully? Answer: No –because when using the combination notation, positional notation parameters must be listed before named notation parameters.

16 home back first prev next last Parameter Passing Will the following call execute successfully? No: You must provide a value for each parameter unless the formal parameter is assigned a default value. –But what if you really want to omit an actual parameter, or you don’t know a value for the parameter? –Specifying default values for formal parameters is discussed next.

17 home back first prev next last Using the DEFAULT Option for IN Parameters You can assign a default value for formal IN parameters. This provides flexibility when passing parameters. The code shows two ways of assigning a default value to an IN parameter. –The assignment operator (:=), as shown for the p_name parameter –The DEFAULT option, as shown for the p_loc parameter

18 home back first prev next last Using the DEFAULT Option for Parameters Below are three ways of invoking the add_dept procedure: –The first example assigns the default values for each parameter. –The second example illustrates a combination of position and named notation to assign values. In this case, using named notation is presented as an example. –The last example uses the default value for the name parameter and the supplied value for the p_loc parameter.

19 home back first prev next last Guidelines for Using the DEFAULT Option for Parameters You cannot assign default values to OUT and IN OUT parameters in the header, but you can in the body of the procedure. CREATE OR REPLACE PROCEDURE aaa(p_a IN OUT NUMBER) IS BEGIN p_a := 200; dbms_output.put_line(p_a); END; DECLARE v_a NUMBER := 100; BEGIN aaa(v_a); END;

20 home back first prev next last Guidelines for Using the DEFAULT Option for Parameters Usually, you can use named notation to override the default values of formal parameters. However, you cannot skip providing an actual parameter if there is no default value provided for a formal parameter. A parameter inheriting a DEFAULT value is different from NULL.

21 home back first prev next last Working with Parameter Errors During Runtime Note: –All the positional parameters should precede the named parameters in a subprogram call. –Otherwise, you receive an error message, as shown in the following example: BEGIN add_dept(name => 'new dept', 'new location'); END; –The following error message is generated:

22 home back first prev next last Terminology Key terms used in this lesson include: –IN Parameter –OUT Parameter –IN OUT Parameter

23 home back first prev next last Summary In this lesson, you learned to: –List the types of parameter modes –Create a procedure that passes parameters –Identify three methods for passing parameters –Describe the DEFAULT option for parameters

24 home back first prev next last Try It / Solve It The exercises in this lesson cover the following topics: –Listing the types of parameter modes –Creating a procedure with parameters –Identifying three methods for passing parameters –Describing the DEFAULT option for parameters