Oracle 9i Collections. Composite types Several variables as single unit ◦ Records  Different datatype variables are combined here  Ex: All fields of.

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

Oracle Object-Relational Model. - Structures : tables, views, indexes, etc. - Operations : actions that manipulate data stored in structures - Integrity.
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 1.
AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
PL/SQL. Introduction to PL/SQL PL/SQL is the procedure extension to Oracle SQL. It is used to access an Oracle database from various environments (e.g.
SQL*PLUS, PLSQL and SQLLDR Ali Obaidi. SQL Advantages High level – Builds on relational algebra and calculus – Powerful operations – Enables automatic.
An Array A sequence of elements of a particular type Each element in the array has an index which gives its position in the sequence An array is declared.
PL/SQL.
Chapter 10 Introduction to Arrays
PL/SQL (Procedural Language extensions to SQL) Prepared by: Manoj Kathpalia Edited by: M V Ramakrishna.
Chapter 10.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Introduction to PL/SQL
C++ for Engineers and Scientists Third Edition
Chapter 9 Introduction to Arrays
Introduction to PL/SQL Lecture 0 – Self Study Akhtar Ali.
Objectives Why PL-SQL ? Language features
PL/SQL Bulk Collections in Oracle 9i and 10g Kent Crotty Burleson Consulting October 13, 2006.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
1 Introduction to PL/SQL. 2  Procedural programming language  Uses detailed instructions  Processes statements sequentially  Combines SQL commands.
6 Copyright © 2009, Oracle. All rights reserved. Working with Composite Data Types.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
CMSC 202 Arrays. Aug 6, Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same type –An.
ARRAYS 1 Week 2. Data Structures  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently 
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Chapter 8: Arrays.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Program with PL/SQL Lesson 5. Working with Composite Data Types.
PL SQL Block Structures. What is PL SQL A good way to get acquainted with PL/SQL is to look at a sample program. PL/SQL combines the data manipulating.
Chapter Twenty One Collection Data Type Objective: – Composite Data Structures – Introduction of Records – Introduction of Collections – Application of.
Pointers OVERVIEW.
LECTURE 1 INTRODUCTION TO PL/SQL Tasneem Ghnaimat.
Advanced Java Programming CS 537 – Data Structures and Algorithms.
Built-in Data Structures in Python An Introduction.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
PL / SQL By Mohammed Baihan. What is PL/SQL? PL/SQL stands for Procedural Language extension of SQL. PL/SQL is a combination of SQL along with the procedural.
Oracle 8i PL/SQL Collections. Collections A Collection is a group of elements of the same kind There are three types of Collections that you can use in.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
Collections Oracle Database PL/SQL 10g Programming Chapter 6.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.
Pascal Programming Arrays and String Type.
Chapter 16 Cursors and Exceptions. Chapter Objectives  Determine when an explicit cursor is required  Declare, open, and close an explicit cursor 
Arrays. Related data items Collection of the same types of data. Static entity – Same size throughout program.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
Oracle10g Developer: PL/SQL Programming1 Objectives SQL queries within PL/SQL Host or bind variables The %TYPE attribute Include queries and control structures.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Using Data Structures in Embedded Programs.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Copyright  Oracle Corporation, All rights reserved. 20 Working with Composite Datatypes.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
6 Copyright © 2004, Oracle. All rights reserved. Working with Composite Data Types.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Chapter 9 Introduction to Arrays Fundamentals of Java.
Composite data types_ PL/SQL table. Composite data types PL/SQL provides three composite data types : TABLE, ROCORD, and VARRAY. Objects of type TABLE.
Sections 10.1 – 10.4 Introduction to Arrays
Pl/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-3
Collection in PL/SQL.
Dynamic Memory Allocation
Working with Composite Datatypes
Chapter 2 Handling Data in PL/SQL Blocks Oracle9i Developer:
PL/SQL Declaring Variables.
Arrays in Java.
Database Programming Using Oracle 11g
Presentation transcript:

Oracle 9i Collections

Composite types Several variables as single unit ◦ Records  Different datatype variables are combined here  Ex: All fields of Students Table ◦ Collections  Combines variables of same type.  Ex. C or Java arrays.  Types of collections 1.Index – by Table (Oracle 7 onwards) 2.Nested Tables (Oracle 8 ) 3.Varray ( Oracle 8)

Index-By Tables Syntax: TYPE IS TABLE OF type INDEX BY BINARY_INTEGER; ◦ Set of Key-Value pairs ◦ indexed using BINARY_INTEGER values which do not need to be consecutive. ◦ No upper bounds ◦ Index starts with 1. ◦ In Oracle 9i Release 2 these have been renamed to Associative Arrays and can be indexed by BINARY INTEGER or VARCHAR2.Associative Arrays DECLARE TYPE table_type IS TABLE OF NUMBER(10) INDEX BY BINARY_INTEGER; v_tab table_type; BEGIN v_tab(7) := 100; DECLARE TYPE table_type IS TABLE OF NUMBER(10) INDEX BY BINARY_INTEGER; v_tab table_type; BEGIN v_tab(7) := 100;

Nested Table Hold an arbitrary number of elements. use sequential numbers (non negative)as subscripts You can define equivalent SQL types, allowing nested tables to be stored in database tables and manipulated through SQL but index-by cannot be stored in DB. During creation the collection must be dense, having consecutive subscripts for the elements. DELETE method to make the collection sparse. The NEXT method overcomes the problems of traversing sparse collections.

DECLARE ◦ TYPE table_type IS TABLE OF NUMBER(10); ◦ v_tab table_type; ◦ v_idx NUMBER; BEGIN ◦ v_tab := table_type(1, 2); ◦ FOR i IN LOOP  v_tab.extend;  v_tab(v_tab.last) := i; ◦ END LOOP; ◦ v_tab.DELETE(3); ◦ v_idx := v_tab.FIRST; ◦ WHILE v_idx IS NOT NULL ◦ LOOP DBMS_OUTPUT.PUT_LINE('The number ' || v_tab(v_idx)); v_idx := v_tab.NEXT(v_idx); ◦ END LOOP ; END; ◦ / The number 1 The number 2 The number 4 The number 5 PL/SQL procedure successfully completed.

Varray A VARRAY is similar to a nested table except you must specifiy an upper bound in the declaration. Like nested tables they can be stored in the database, but unlike nested tables individual elements cannot be deleted so they remain dense. Syntax: ◦ TYPE type_name {VARRAY | VARYING ARRAY } (max_size) OF element_type [NOT NULL]; ◦ Ex: ◦ TYPE NUMlist VARRAY(10) OF students.Roll% TYPE NOT NULL;  V_num NUMlist;  V_num NUMlist := NUMlist(1.2) ; //constructor initialization

Index- BYNested TablesVarrays Cannot be stored in DBCan be Keys can be positive or negative Positive onlypositive only No explicit max Size Have explicit max Size Can be sparse with non- sequential keys Always sequential and have space allocated for each value Cannot be automatically NULL Can be NO_DATA _FOUND is raised if nonexistant data is referred SUBSCRIPT_BEYOND_COU NT Can be declared in PL/SQL block only Can be declared in PL/SQL block or outside using CREATE TYPE Elements are assigned directly without initialization The Table must be initialized and extended before elements can be assigned The Varray must be initialized before elements can be assigned

Collection Methods A variety of methods exist for collections, but not all are relevant for every collection type. EXISTS(n) - Returns TRUE if the specified element exists. COUNT - Returns the number of elements. LIMIT - Returns max num of elements for a VARRAY, or NULL for nested tables. FIRST - Returns the index of the first element in the collection. LAST - Returns the index of the last element in the collection. PRIOR(n) - Returns the index of the element prior to the specified element. NEXT(n) - Returns the index of the next element after the specified element. EXTEND - Appends a single null element to the collection. EXTEND(n) - Appends n null elements to the collection. EXTEND(n1,n2) - Appends n1 copies of the n2th element to the collection. TRIM - Removes a single element from the end of the collection. TRIM(n) - Removes n elements from the end of the collection. DELETE - Removes all elements from the collection. DELETE(n) - Removes element n from the collection. DELETE(n1,n2) - Removes all elements from n1 to n2 from the collection.

Multilevel Collections