Exforsys.com
 
Home Tutorials Oracle 9i
 

Tutorial 12: Oracle 9i: PL/SQL Collections

 

Tutorial 12: Oracle 9i: PL/SQL Collections

Page 1 of 2
This tutorial covers Defining and Using Collections - Declaring, Initializing, and Referencing PL/SQL Collections and Collection Methods - Using the Collection Methods.


Oracle 9i: PL/SQL Collections


Introduction

Version 8.0 and higher versions of Oracle are referred to as ORDBMS (Object-Relational Database Management System). The traditional Oracle database management system is extended to include Object-Oriented Concepts and structures such as abstract data types, nested tables, varying arrays, object views and references.

Abstract Datatypes


Also called user-defined datatypes are those that consist one or more subtypes. Apart from using standard oracle datatypes they can also use other abstract datatypes. An abstract datatype created can be reused like other standard datatypes.

Creating Abstract Datatypes


The following screenshots and other code fragments explain about how to create abstract datatypes. Also I explained about how to create tables using abstract datatypes.




SQL > DESC CUSTOMER

Name Null? Type
----------------------------------------- -------- -----------------
CUSTID NUMBER (4)
CUSTNAME VARCHAR2 (20)
ADDRESS CUST_ADDRESS_TY


SQL > SELECT COLUMN_NAME, DATA_TYPE FROM USER_TAB_COLUMNS
2 WHERE TABLE_NAME = 'CUSTOMER';

COLUMN_NAME DATA_TYPE
---------------------------------------------------------------
CUSTID NUMBER
CUSTNAME VARCHAR2
ADDRESS CUST_ADDRESS_TY



Inserting Data into tables with Abstract Data Type


For Placing records into a table containing Abstract Data Types, we use a special method called constructor method. A constructor method is created by Oracle when you create an abstract datatype.

Example:




Displaying Records from the table




PL/SQL Collections:



A collection is a data structure that acts like an array. A collection is defined as an ordered group of elements, all of the same type. Individual element in a collection can be accessed by using index like an array in C. There are three types of collections in oracle



Nested Tables


A nested table is defined as table within another table. They can also be called one-column database tables. A nested table is collection of rows, represented as column within the table; nested table may contain many rows. Using nested tables we can store one-to-many relationships within one table. You can have multiple rows in the nested table for each row in the main table A nested table is like one-dimensional array but it has the following differences. Size of an array is fixed but nested table can grow to any size. The subscript of an Array is consecutive but subscript of a nested table may not be consecutive.


Next Page: Tutorial 12: Oracle 9i: PL/SQL Collections - Page 2


Read Next: Tutorial 13: Oracle 9i : Procedures and Functions



 

 

Comments


Abdul Rahman said:

  Oracle 9i Collections Made Easy, Excellent Collection of Easy Reference Stuff. Keep up the great work Exforsys Team.Best of luck :)
August 4, 2006, 2:08 am

Radhika V said:

  Excellent Work. You could also discuss other dml commands on varrays such as updating, deleting and accessing each and every element of varray :)
August 11, 2006, 3:14 am

itanand said:

  Excellent work!! :-*
September 20, 2006, 2:36 am

harishb said:

  how to handle the nulls in oracle?
December 11, 2006, 2:35 am

Imtiaz ali said:

  Associate arrays or Index-by table is not understandable. This is the only topic found difficult to understand otherwise complete tutorial is fine.
May 30, 2007, 9:49 pm

arulkumar said:

  i'm beginner to oracle .it ll be very useful for beginners like me
August 16, 2007, 11:31 pm

bharat kumar said:

  im a beginner of oracle and these sessions are really great for people like me to get about basics
November 27, 2007, 6:44 am

eric said:

  this article is easy to follow except the "Associative arrays (or) Index-by tables" part.

August 11, 2008, 4:25 am

eric said:

  this article is perfect for beginners
August 11, 2008, 4:29 am

Abiash said:

  Excellent tutorial. i don't know what to say other than thank you very much for this amazing informative section.

November 12, 2008, 2:17 am

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape