Persistent State of Package Variables. 2 home back first prev next last What Will I Learn? Identify persistent states of package variables Control the.

Slides:



Advertisements
Similar presentations
Chapter 8 Advanced SQL Pearson Education © Chapter 8 - Objectives u How to use the SQL programming language u How to use SQL cursors u How to create.
Advertisements

Oracle PL/SQL IV Exceptions Packages.
AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
SQL*PLUS, PLSQL and SQLLDR Ali Obaidi. SQL Advantages High level – Builds on relational algebra and calculus – Powerful operations – Enables automatic.
ITEC113 Algorithms and Programming Techniques
Summary of the lecture We discussed –variable scope –instance variable declarations –variable lifetime.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
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.
3 Copyright © 2004, Oracle. All rights reserved. Creating Packages.
Why Behavioral Wait statement Signal Timing Examples of Behavioral Descriptions –ROM.
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:
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
1 PL/SQL programming Procedures and Cursors Lecture 1 Akhtar Ali.
Cursors in Pl/SQL Database 1. Practice. Sample Database The schema of the sample database is the following: Drinkers (name, occupation, birthday, salary)
Bordoloi and Bock CURSORS. Bordoloi and Bock CURSOR MANIPULATION To process an SQL statement, ORACLE needs to create an area of memory known as the context.
Benefits of PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –List and explain the benefits of PL/SQL –List.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Good Programming Practices. 2 home back first prev next last What Will I Learn? List examples of good programming practices Accurately insert comments.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 7 PL/SQL Packages.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
PL/SQLPL/SQL Oracle11g : PL/SQL Programming Chapter 6 Functions.
Using Procedures & Functions Oracle Database PL/SQL 10g Programming Chapter 9.
PRACTICE OVERVIEW PL/SQL Part Examine this package specification and body: Which statement about the V_TOTAL_BUDGET variable is true? A. It must.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Stored Procedures Week 9. Test Details Stored Procedures SQL can call code written in iSeries High Level Languages –Called stored procedures SQL has.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (there is an audio component to this eLesson) © Dr.
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.
Database Management COP4540, SCS, FIU Oracle PL/SQL (Ch 10.5)
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.
Commercial RDBMSs Access and Oracle. Access DBMS Architchecture  Can be used as a standalone system on a single PC: -JET Engine -Microsoft Data Engine.
Module 3 Designing and Implementing Tables. Module Overview Designing Tables Working with Schemas Creating and Altering Tables.
11 Copyright © 2004, Oracle. All rights reserved. Dealing with Database Corruption.
1 PL\SQL Dev Templates. 2 TEMPLATE DEFINITION Whenever you create a new program unit, its initial contents are based upon a template which contains pre-defined.
Creating DDL and Database Event Triggers. 2 home back first prev next last What Will I Learn? Describe events that cause DDL and database event triggers.
What is a Package? A package is an Oracle object, which holds other objects within it. Objects commonly held within a package are procedures, functions,
Using SQL in PL/SQL ITEC 224 Database Programming.
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.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
SnapView Clones Upon completion of this module, you should be able to:
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.
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.
Cursors For viewing and updating. Cursors How to step through the returned set of rows.
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.
implicit and an explicit cursor
Transactions, Roles & Privileges Oracle and ANSI Standard SQL Lecture 11.
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.
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.
PL/SQL programming Procedures and Cursors Lecture 1 [Part 2]
15 Copyright © 2004, Oracle. All rights reserved. Debugging Triggers.
Chapter 8 Advanced SQL Pearson Education © Chapter 8 - Objectives How to use the SQL programming language How to use SQL cursors How to create stored.
8 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Course ILT Using complex selection structures Unit objectives Include radio buttons and check boxes in an interface, create and call a user- defined Sub.
Oracle9i Developer: PL/SQL Programming Chapter 6 PL/SQL Packages.
1 Copyright © 2004, Oracle. All rights reserved. PL/SQL Programming Concepts: Review.
4 Copyright © 2009, Oracle. All rights reserved. Working with Packages.
PL/SQL.
Creating Packages.
Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.
Database Management Systems 2
Chapter 8 Advanced SQL.
Information Management
Chapter 8 Advanced SQL Pearson Education © 2009.
Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.
Prof. Arfaoui. COM390 Chapter 7
Presentation transcript:

Persistent State of Package Variables

2 home back first prev next last What Will I Learn? Identify persistent states of package variables Control the persistent state of a package cursor

3 home back first prev next last Why Learn It? Suppose you connect to the database and modify the value in a package variable, for example from 10 to 20. Later, you (or someone else) invoke the package again to read the value of the variable. What will you/they see: 10 or 20? It depends! Real applications often invoke the same package many times. It is important to understand when the values in package variables are kept (persist) and when they are lost.

4 home back first prev next last Package State The collection of package variables and their current values define the package state. The package state is: –Initialized when the package is first loaded –Persistent (by default) for the life of the session  Stored in the session’s private memory area  Unique to each session even if the second session is started by the same user  Subject to change when package subprograms are called or public variables are modified. –Other sessions each have their own package state, and will not see our changes.

5 home back first prev next last Example Here is a simple package which initializes a single global variable and contains a procedure to update it: SCOTT and JONES will call the procedure to update the variable.

6 home back first prev next last The following sequence of events occurs

7 home back first prev next last Explanation of the events on the previous slide At 9:00: Scott connects and reads the variable, seeing the initialized value 10. At 9:30: Jones connects and also reads the variable, also seeing the initialized value 10. At this point there are two separate and independent copies of the value, one in each session’s private memory area. Jones now updates his own session’s value to 20 via the procedure. Scott then re-reads the variable but does not see Jones’s change. At 9:35: Scott updates his own session’s value to 50. Again, Jones cannot see the change. At 10:00: Scott disconnects and reconnects, creating a new session. At 10:05: Scott reads the variable and sees the initialized value 10. These changes would not be visible in other sessions even if both sessions are connected under the same username.

8 home back first prev next last Persistent State of a Package Cursor A cursor declared in the package specification is a type of global variable, and follows the same persistency rules as any other variable. –A cursor’s state is not defined by a single numeric or other value. A cursor’s state consists of the following attributes:  whether the cursor is open or closed  (if open) how many rows have been fetched from the cursor (%ROWCOUNT) and whether or not the most recent fetch was successful (%FOUND or %NOTFOUND). The next three slides show the definition of a cursor and its repeated use in a calling application.

9 home back first prev next last Persistent State of a Package Cursor Package Specification: The cursor declaration is declared globally within the package specification. Therefore any or all of the package procedures can reference it.

10 home back first prev next last Persistent State of a Package Cursor Package Body:

11 home back first prev next last Invoking CURS_PKG Step 1 opens the cursor. Step 2 (in a loop) fetches and displays the next three rows from the cursor until all rows have been fetched. Step 3 closes the cursor.

12 home back first prev next last Invoking CURS_PKG The first looped call to fetch_n_rows displays the first three rows. The second time round the loop, the next three rows are fetched and displayed. And so on. This technique is often used in applications which need to FETCH a large number of rows from a cursor, but can only display them to the user one screenful at a time.

13 home back first prev next last Terminology Key terms used in this lesson include: –Package state

14 home back first prev next last Summary In this lesson, you learned to: –Identify persistent states of package variables –Control the persistent state of a package cursor

15 home back first prev next last Try It / Solve It The exercises in this lesson cover the following topics: –Identifying persistent states of package variables –Controlling the persistent state of a package cursor