Collections Oracle Database PL/SQL 10g Programming Chapter 6.

Slides:



Advertisements
Similar presentations
Oracle Object-Relational Model. - Structures : tables, views, indexes, etc. - Operations : actions that manipulate data stored in structures - Integrity.
Advertisements

Arrays.
SQL Objects and PL/SQL. Who am I ?  Gary Myers  Oracle developer since 1994  Database Consultant with SMS M&T  Blogger since 2004 Now at blog.sydoracle.com.
PL/SQL.
Chapter 10 Introduction to Arrays
Introduction to Domains
Chapter 5 Types. 5-2 Topics in this Chapter Values vs. Variables Types vs. Representations Type Definition Operators Type Generators SQL Facilities.
Chapter 10.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 8 Advanced SQL.
Introduction to PL/SQL
Chapter 9 Introduction to Arrays
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Cursors in Pl/SQL Database 1. Practice. Sample Database The schema of the sample database is the following: Drinkers (name, occupation, birthday, salary)
PL/SQL Bulk Collections in Oracle 9i and 10g Kent Crotty Burleson Consulting October 13, 2006.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 8 Advanced SQL.
Exceptions Oracle Database PL/SQL 10g Programming Chapter 7.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Lecture 17 Object relational databases. 2 Example Table Creation based on UDT CREATE TABLE Person ( info PersonType, CONSTRAINT DOB_Check CHECK(dateOfBirth.
6 Copyright © 2009, Oracle. All rights reserved. Working with Composite Data Types.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
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.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
Records Oracle Database PL/SQL 10g Programming Chapter 5.
© 1999, by Que Education and Training, Chapter 8, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
CS Midterm Study Guide Fall General topics Definitions and rules Technical names of things Syntax of C++ constructs Meaning of C++ constructs.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
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.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Chapter 6 Procedural Language SQL and Advanced SQL Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
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.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
Dynamic SQL Oracle Database PL/SQL 10g Programming Chapter 13.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
Using SQL in PL/SQL ITEC 224 Database Programming.
Chapter 13: Structures. In this chapter you will learn about: – Single structures – Arrays of structures – Structures as function arguments – Linked lists.
1 CSCE Database Systems Anxiao (Andrew) Jiang The Database Language SQL.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
Introduction to PL/SQL Francis Thottungal. The outline The basic PL/SQL code structure is : DECLARE -- optional, which declares and define variables,
Program with PL/SQL Lesson 3. Interacting with the Oracle Server.
Oracle9i Developer: PL/SQL Programming Chapter 5 Functions.
Last Updated : 27 th April 2004 Center of Excellence Data Warehousing Group Teradata RDBMS Concepts.
6 Copyright © 2004, Oracle. All rights reserved. Working with Composite Data Types.
Oracle 9i Collections. Composite types Several variables as single unit ◦ Records  Different datatype variables are combined here  Ex: All fields of.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Chapter 9 Introduction to Arrays Fundamentals of Java.
Preface IIntroduction Course Objectives I-2 Oracle Complete Solution I-3 Course Agenda I-4 Tables Used in This Course I-5 The Order Entry Schema I-6 The.
C++ for Engineers and Scientists Second Edition Chapter 12 Pointers.
Pl/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-3
Relational Database Design
Collection in PL/SQL.
Oracle11g: PL/SQL Programming Chapter 4 Cursors and Exception Handling.
Lists in Python.
Chapter 2 Handling Data in PL/SQL Blocks Oracle9i Developer:
Object Oriented Programming in java
Topics Sequences Introduction to Lists List Slicing
Chapter 8 Advanced SQL.
PL/SQL Declaring Variables.
Database Systems: Design, Implementation, and Management Tenth Edition
Topics Sequences Introduction to Lists List Slicing
Database Programming Using Oracle 11g
Presentation transcript:

Collections Oracle Database PL/SQL 10g Programming Chapter 6

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 2 Collections Collection Types Collection Types VARRAY Collections VARRAY Collections Nested Table Collections Nested Table Collections Associative Array Collections Associative Array Collections Collection API Collection API

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 3 Collections Collection Types: Definition Collections are lists. Collections are lists. Collections are ordered or unordered. Collections are ordered or unordered. Ordered lists are indexed by numbers. Ordered lists are indexed by numbers. Unordered lists are indexed by unique strings. Unordered lists are indexed by unique strings. Collection elements can be: Collection elements can be: Scalar variables Scalar variables Compound variables Compound variables

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 4 Collections Collection Types: VARRAY VARRAY collections are densely populated structures, indexed by sequential numbers. VARRAY collections are densely populated structures, indexed by sequential numbers. VARRAY collections have an initial maximum size. VARRAY collections have an initial maximum size. VARRAY collections can be used as column data types. VARRAY collections can be used as column data types.

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 5 Collections Collection Types: Nested Table Nested tables are densely populated structures, indexed by sequential numbers. Nested tables are densely populated structures, indexed by sequential numbers. Nested tables are have no maximum size. Nested tables are have no maximum size. Nested tables can be used as column data types. Nested tables can be used as column data types.

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 6 Collections Collection Types: Associative Arrays Associative arrays are sparsely populated structures, indexed by unique numbers or strings. Associative arrays are sparsely populated structures, indexed by unique numbers or strings. Associative arrays have no maximum size. Associative arrays have no maximum size. Associative arrays cannot be used as column data types. Associative arrays cannot be used as column data types.

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 7 Collections Collection Types: Multiset Operators MULTISET EXCEPT This operator removes one set from another, like the SQL MINUS operator. MULTISET EXCEPT This operator removes one set from another, like the SQL MINUS operator. MULTISET INTERSECT This operator takes two sets and merges them into a new set that contains one copy of elements found in both original sets, like the SQL INTERSECT operator. MULTISET INTERSECT This operator takes two sets and merges them into a new set that contains one copy of elements found in both original sets, like the SQL INTERSECT operator. MULTISET UNION This operator takes two sets and merges them into a new set without eliminating duplicate values, like the UNION ALL operator. MULTISET UNION This operator takes two sets and merges them into a new set without eliminating duplicate values, like the UNION ALL operator. SET This operator removes duplicates from a set and acts like the DISTINCT operator in a SQL statement. SET This operator removes duplicates from a set and acts like the DISTINCT operator in a SQL statement.

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 8 Collections VARRAY Collection Types: Rules VARRAY data types can be defined: VARRAY data types can be defined: As PL/SQL user-defined types. As PL/SQL user-defined types. As SQL collection data types of scalar variables. As SQL collection data types of scalar variables. As SQL collection data types of compound, object type, variables. As SQL collection data types of compound, object type, variables. VARRAY data types require explicit construction. VARRAY data types require explicit construction. VARRAY data types allocate space at construction or by calling the Oracle Collection API EXTEND methods to allocate space for an element or set of elements. VARRAY data types allocate space at construction or by calling the Oracle Collection API EXTEND methods to allocate space for an element or set of elements.

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 9 Collections VARRAY Collection Types: SQL Declaration -- Declare VARRAY SQL data type. CREATE [OR REPLACE] TYPE number_list AS VARRAY(3) OF NUMBER;

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 10 Collections VARRAY Collection Types: PL/SQL Declaration DECLARE -- Declare VARRAY PL/SQL data type. -- Declare VARRAY PL/SQL data type. TYPE number_list IS VARRAY(3) OF NUMBER; TYPE number_list IS VARRAY(3) OF NUMBER; -- Create a list without any allocated space. -- Create a list without any allocated space. empty_scalar_list NUMBER_LIST := NUMBER_LIST(); empty_scalar_list NUMBER_LIST := NUMBER_LIST(); -- Create a list of NULL values with two allocated space. -- Create a list of NULL values with two allocated space. null_scalar_list NUMBER_LIST := NUMBER_LIST(NULL,NULL); null_scalar_list NUMBER_LIST := NUMBER_LIST(NULL,NULL); -- Create a list of values with three allocated space. -- Create a list of values with three allocated space. value_scalar_list NUMBER_LIST := NUMBER_LIST(1,2,3); value_scalar_list NUMBER_LIST := NUMBER_LIST(1,2,3);BEGIN … next_slide … … next_slide …END;/

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 11 Collections VARRAY Collection Types: PL/SQL Assignment DECLARE … prior_slide … … prior_slide …BEGIN empty_scalar_list.EXTEND; empty_scalar_list.EXTEND; empty_scalar_list(1) := 1829; empty_scalar_list(1) := 1829;END;/

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 12 Collections Nested Table Collection Types: Rules Nested table data types can be defined: Nested table data types can be defined: As PL/SQL user-defined types. As PL/SQL user-defined types. As SQL collection data types of scalar variables. As SQL collection data types of scalar variables. As SQL collection data types of compound, object type, variables. As SQL collection data types of compound, object type, variables. Nested table data types require explicit construction. Nested table data types require explicit construction. Nested table data types allocate space at construction or by calling the Oracle Collection API EXTEND methods to allocate space for an element or set of elements. Nested table data types allocate space at construction or by calling the Oracle Collection API EXTEND methods to allocate space for an element or set of elements.

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 13 Collections Nested Table Collection Types: SQL Declaration -- Declare VARRAY SQL data type. CREATE [OR REPLACE] TYPE number_list AS TABLE OF NUMBER;

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 14 Collections Nested Table Collection Types: PL/SQL Declaration DECLARE -- Declare VARRAY PL/SQL data type. -- Declare VARRAY PL/SQL data type. TYPE number_list IS TABLE OF NUMBER; TYPE number_list IS TABLE OF NUMBER; -- Create a list without any allocated space. -- Create a list without any allocated space. empty_scalar_list NUMBER_LIST := NUMBER_LIST(); empty_scalar_list NUMBER_LIST := NUMBER_LIST(); -- Create a list of NULL values with two allocated space. -- Create a list of NULL values with two allocated space. null_scalar_list NUMBER_LIST := NUMBER_LIST(NULL,NULL); null_scalar_list NUMBER_LIST := NUMBER_LIST(NULL,NULL); -- Create a list of values with three allocated space. -- Create a list of values with three allocated space. value_scalar_list NUMBER_LIST := NUMBER_LIST(1,2,3); value_scalar_list NUMBER_LIST := NUMBER_LIST(1,2,3);BEGIN … next_slide … … next_slide …END;/

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 15 Collections Associative Array Collection Types: Rules Associative Array data types can be defined as PL/SQL user-defined types. Associative Array data types can be defined as PL/SQL user-defined types. Associative Array data types cannot be defined as SQL collection data types. Associative Array data types cannot be defined as SQL collection data types. Associative Array data types do not require explicit construction. Associative Array data types do not require explicit construction. Associative Array data types require element by element assignment, or bulk assignments. Associative Array data types require element by element assignment, or bulk assignments. Associative Array data types do not require explicit space allocation. Associative Array data types do not require explicit space allocation. Associative Array data types can use the Oracle Collection API. Associative Array data types can use the Oracle Collection API.

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 16 Collections Nested Table Collection Types: PL/SQL Usage DECLARE -- Declare VARRAY PL/SQL data type. -- Declare VARRAY PL/SQL data type. TYPE number_list IS TABLE OF NUMBER TYPE number_list IS TABLE OF NUMBER INDEX BY BINARY_INTEGER; INDEX BY BINARY_INTEGER; -- Declare a variable. -- Declare a variable. empty_scalar_list NUMBER_LIST; empty_scalar_list NUMBER_LIST;BEGIN empty_scalar_list(1) := 1829; empty_scalar_list(1) := 1829;END;/

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 17 Collections COLLECTION API: Methods COUNT a method that returns the number of elements in a collection. COUNT a method that returns the number of elements in a collection. DELETE(n) a method that takes a single formal parameter that is an index value, and it removes the element pointed to by the equivalent index value. DELETE(n) a method that takes a single formal parameter that is an index value, and it removes the element pointed to by the equivalent index value. DELETE(n,m) a method that takes two formal parameter index values, and it removes a range of elements pointed to by the equivalent index value. DELETE(n,m) a method that takes two formal parameter index values, and it removes a range of elements pointed to by the equivalent index value. EXISTS(n) a method that takes one formal parameter index value, and returns TRUE if found in the collection and FALSE if not. If the collection is a null element structure, the method also returns FALSE. EXISTS(n) a method that takes one formal parameter index value, and returns TRUE if found in the collection and FALSE if not. If the collection is a null element structure, the method also returns FALSE.

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 18 Collections COLLECTION API: Methods EXTEND a method that takes no formal parameter and extends space for one new element. EXTEND a method that takes no formal parameter and extends space for one new element. EXTEND(n) a method that takes one formal parameter, which designates how many spaces to extend the collection. EXTEND(n) a method that takes one formal parameter, which designates how many spaces to extend the collection. EXTEND(n,m) a method that takes two formal parameters; the first designates how many spaces to extend, and the second identifies an index to copy into the newly indexed spaces. EXTEND(n,m) a method that takes two formal parameters; the first designates how many spaces to extend, and the second identifies an index to copy into the newly indexed spaces. FIRST a method that takes no formal parameter and returns the first index value, this is the lowest number for numeric indexes and lowest value string for string indexes. FIRST a method that takes no formal parameter and returns the first index value, this is the lowest number for numeric indexes and lowest value string for string indexes. LAST a method that takes no formal parameter and returns the last index value by using opposite rules to the FIRST method. LAST a method that takes no formal parameter and returns the last index value by using opposite rules to the FIRST method.

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 19 Collections COLLECTION API: Methods LIMIT a method that returns the highest allowed element number in a VARRAY collection. LIMIT a method that returns the highest allowed element number in a VARRAY collection. NEXT(n) a method that takes a single formal parameter that is an index value, and it returns the next value in the collection. NEXT(n) a method that takes a single formal parameter that is an index value, and it returns the next value in the collection. PRIOR(n) a method that takes a single formal parameter that is an index value, and returns the prior indexed value in the collection. PRIOR(n) a method that takes a single formal parameter that is an index value, and returns the prior indexed value in the collection. TRIM a method that takes no formal parameter, and removes the highest subscripted value from a collection. TRIM a method that takes no formal parameter, and removes the highest subscripted value from a collection. TRIM(n) a method that takes one formal parameter, which is an INTEGER ; and it removes that number of subscripted values from the end of a collection. TRIM(n) a method that takes one formal parameter, which is an INTEGER ; and it removes that number of subscripted values from the end of a collection.

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 20 Collections COLLECTION API: Exceptions COLLECTION_IS_NULL COLLECTION_IS_NULL Raised when attempting to access a null collection. Raised when attempting to access a null collection. NO_DATA_FOUND NO_DATA_FOUND Raised when attempting to access values that are not present in an initialized collection. Raised when attempting to access values that are not present in an initialized collection. SUBSCRIPT_BEYOND_COUNT SUBSCRIPT_BEYOND_COUNT Raised when attempting to access beyond the highest subscripted value. Raised when attempting to access beyond the highest subscripted value. SUBSCRIPT_OUTSIDE_LIMIT SUBSCRIPT_OUTSIDE_LIMIT Raised when attempting to access beyond a VARRAY index value limit. Raised when attempting to access beyond a VARRAY index value limit. VALUE_ERROR VALUE_ERROR Raised when attempting to cast an incorrect data type to the index type of the subscript. Raised when attempting to cast an incorrect data type to the index type of the subscript.

2006 Oracle Database PL/SQL 10g Programming (Chapter 6)Page 21 Summary Collection Types Collection Types VARRAY Collections VARRAY Collections Nested Table Collections Nested Table Collections Associative Array Collections Associative Array Collections Collection API Collection API