Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

Oracle 9i PL/SQL Collections

By Exforsys | on March 6, 2005 |
Oracle 9i
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

From the above example it is clear that simple DESC command will not give us any detail about Abstract Data Type. To display the details about an abstract datatype use the following syntax.

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.

Creating Nested Tables

The following example explain how to create a table type and then nest it in a table



Following syntax is used to display columns of the above table we write.

SQL > SELECT COLUMN_NAME, DATA_TYPE FROM USER_TAB_COLUMNS;
SQL > SELECT TYPECODE, ATTRIBUTES FROM USER_TYPES;

TYPECODE ATTRIBUTES
—————————— ———-
OBJECT 2
COLLECTION 0

To insert values into the above table we use the below given syntax

To query a nested table Oracle provides a new function THE. To select data from a field in the nested table we must have to flatten the table first. Function THE is used for this purpose.


Varrays:

Is short form for variable sized arrays. They are used to store repeating attributes in a table. Varying arrays can be created based on standard datatypes of Oracle or by using abstract datatypes.
A varying array take fixed number of elements when it is created, which can be changed at runtime. The subscript used by Varrays is sequential. We have to decide the maximum number of elements for the varying array.

Creating VARRAYS

Below given example explains creation and usage of VARRYS. Let us consider an organization developing multiple projects simultaneously. Each project has few team members and these members report to a team leader. We will have a varying array for storing members’ names. Another table is created for storing the project details.

To describe table we use

SQL > DESC PROJECT
Name Null? Type
—————————————– ——– —————-
PROJID NUMBER (5)
PROJNAME VARCHAR2 (25)
TEAMLEAD VARCHAR2 (20)
TEAMMEMBERS MEMBERS_VA

We use the following query to see the datatype of MEMBERS_VA


Inserting Records into Varying Arrays.

Associative arrays (or) Index-by tables:

They are sets of key-value pairs. The keys are maintained unique. The key can be either an integer or a string. The unique key is created using primary key from a table. The types raw , longraw , rowid etc are not allowed as keys.

Creating Associative Arrays

« « Microsoft Analysis Services Installation
MSAS : Introducing Analysis Manager Wizards » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 391 Followers
  • Popular
  • Recent
  • Oracle 9i Tables and Constraints

    February 2, 2005 - 0 Comment
  • Introduction to Oracle 9i SQL, PLSQL, and SQL *Plus

    October 24, 2004 - 0 Comment
  • More Oracle 9i Database Objects

    February 14, 2005 - 0 Comment
  • Oracle 9i Software Installation, SQL, PLSQL and SQL *Plus References

    October 25, 2004 - 0 Comment
  • Building PL/SQL Blocks in Oracle 9i

    February 16, 2005 - 0 Comment
  • Oracle 9i PL/SQL Control Structures

    February 26, 2005 - 0 Comment
  • Oracle 9i Cursors

    February 27, 2005 - 0 Comment
  • Download example SQL Scripts used in Oracle 9i Tutorials

    March 3, 2005 - 0 Comment
  • Oracle 9i Exception Handling

    March 3, 2005 - 0 Comment
  • Oracle 9i Procedures and Functions

    March 13, 2005 - 0 Comment
  • Oracle 9i Utilities

    April 30, 2005 - 0 Comment
  • Oracle 9i Packages

    April 7, 2005 - 0 Comment
  • Oracle 9i Database Triggers

    March 28, 2005 - 0 Comment
  • Oracle 9i Procedures and Functions

    March 13, 2005 - 0 Comment
  • Oracle 9i Exception Handling

    March 3, 2005 - 0 Comment
  • Download example SQL Scripts used in Oracle 9i Tutorials

    March 3, 2005 - 0 Comment
  • Oracle 9i Cursors

    February 27, 2005 - 0 Comment
  • Oracle 9i PL/SQL Control Structures

    February 26, 2005 - 0 Comment
  • Building PL/SQL Blocks in Oracle 9i

    February 16, 2005 - 0 Comment
  • More Oracle 9i Database Objects

    February 14, 2005 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Oracle 9i Utilities
  • Oracle 9i Packages
  • Oracle 9i Database Triggers
  • Oracle 9i Procedures and Functions
  • Oracle 9i Exception Handling

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT