0% found this document useful (0 votes)
84 views

PL-SQL Tables

This document discusses PL/SQL tables, including: - PL/SQL tables reside in the private global area on the Oracle database and can only be manipulated from within PL/SQL code. - PL/SQL tables are one-dimensional, unbounded, sparse, and homogenous - unlike SQL tables and PL/SQL arrays. - DML statements like SELECT, INSERT, UPDATE and DELETE cannot be used directly with PL/SQL tables. - To declare a PL/SQL table, a table type must first be defined specifying the data type, then a table is declared based on that table type.

Uploaded by

Ajith Smart
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

PL-SQL Tables

This document discusses PL/SQL tables, including: - PL/SQL tables reside in the private global area on the Oracle database and can only be manipulated from within PL/SQL code. - PL/SQL tables are one-dimensional, unbounded, sparse, and homogenous - unlike SQL tables and PL/SQL arrays. - DML statements like SELECT, INSERT, UPDATE and DELETE cannot be used directly with PL/SQL tables. - To declare a PL/SQL table, a table type must first be defined specifying the data type, then a table is declared based on that table type.

Uploaded by

Ajith Smart
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Oracle PL/SQL Tables – KIMMTECH.

COM

Introduction

In our tenth lesson we will cover the following topics:

Pl/SQL Tables
Characteristics of PL/SQL Tables
Using DML Statements with PL/SQL Tables
How to declare a PL/SQL table

PL/SQL Tables

PL/SQL table are only available with PL/SQL version 2 and greater. PL/SQL tables reside in the
Private Global area (PGA) on the Oracle database instance. They only exist as a server side
structure and as such it is not possible to manipulate PL/SQL tables in the Oracle Developer
2000 environment.

Characteristics of PL/SQL Tables

PL/SQL tables are an enigma, they are like an array but they are not, they are also like a table
but they are not!

So what are they?

I will explain the characteristics of PL/SQL tables and arrays and SQL tables, so that you will
understand the differences so you will know how and when to use PL/SQL in your programs.

They are one dimensional, a PL/SQL table can only have one column, like a one dimensional
array. Unlike arrays that can be defined with more than one dimension.!

They are unbounded. What this means is that there is no limit to the number of rows in a
PL/SQL table. The PL/SQL table grows dynamically as you add more rows to the table. Unlike an
array that must be defined at creation!

They are sparse. This means that a row exists in the table only when a value has been
assigned to a row. Additionally rows do not need to be assigned sequentially. We can assign
row 10, 30 then rows 10231. With no values assigned between! Unlike an array, which is
regarded as a dense structure. When an array is defined, all the cells in the array are assigned
memory.

They are homogenous. Because they can only have a single column, all the rows in the PL/SQL
table contain the same datatype. Hence homogenous.

Note: With the introduction of PL/SQL Version 2.3 you can have PL/SQL tables of records. The
resulting table is still homogenous. Each row contains the same set of columns.

PL/SQL tables have a single indexing mode, called BINARY_INTEGER. This acts as the primary
key of the PL/SQL table. As the index is an integer, it is not possible to have a row defined as
table(23.3) but table(-23) is possible.

Using DML statements with PL/SQL tables

PL/SQL tables differ from Oracle tables such that:


There is no concept of transaction integrity with PL/SQL tables.

You cannot SELECT from a PL/SQL table, you must use PL/SQL loops to move through the table
one row at a time.

You cannot INSERT, UPDATE or DELETE from a PL/SQL table.

Note: With PL/SQL Version 2.3 a DELETE operator now exists.

How to declare a PL/SQL table

As with PL/SQL records a PL/SQL table is declared in two stages

You must define the PL/SQL table structure, e.g. NUMBER, VARCHAR2 etc. using the table TYPE
statement.

Declare the table based on that table type. The declaration of a PL/SQL table is a specific
instance of a table type.

The table type statement has the following format.

Code:
TYPE names IS TABLE OF varchar2 [NOT NULL]
INDEX BY BINARY_INTEGER

This has defined a table type called names consisting of the datatype varchar2. The NOT NULL
is optional.

The datatypes used in the table type can be one of the following.

Scalar datatypes i.e. NUMBER, VARCHAR2, DATE or BOOLEAN.

Anchored datatypes as we have discussed in our previous lessons.

The format to create a PL/SQL table is

Code:
<table_name> <table_type>;

Using our example

Code:
customer_names names;

This has declared a PL/SQL table called customer_names based on the names structure
defined earlier.

You might also like