Selecting Nested Table Elements : Nested Table Column « Collections « Oracle PL/SQL Tutorial

Home
Oracle PL/SQL Tutorial
1.Introduction
2.Query Select
3.Set
4.Insert Update Delete
5.Sequences
6.Table
7.Table Joins
8.View
9.Index
10.SQL Data Types
11.Character String Functions
12.Aggregate Functions
13.Date Timestamp Functions
14.Numerical Math Functions
15.Conversion Functions
16.Analytical Functions
17.Miscellaneous Functions
18.Regular Expressions Functions
19.Statistical Functions
20.Linear Regression Functions
21.PL SQL Data Types
22.PL SQL Statements
23.PL SQL Operators
24.PL SQL Programming
25.Cursor
26.Collections
27.Function Procedure Packages
28.Trigger
29.SQL PLUS Session Environment
30.System Tables Data Dictionary
31.System Packages
32.Object Oriented
33.XML
34.Large Objects
35.Transaction
36.User Privilege
Oracle PL/SQL Tutorial » Collections » Nested Table Column 




You select the elements in a nested table using a SELECT statement.

SQL>
SQL>
SQL> CREATE Or Replace TYPE AddressType AS OBJECT (
  2    street VARCHAR2(15),
  3    city   VARCHAR2(15),
  4    state  CHAR(2),
  5    zip    VARCHAR2(5)
  6  );
  7  /

SQL>
SQL> CREATE Or Replace TYPE nested_table_AddressType AS TABLE OF AddressType;
  2  /

Type created.

SQL>
SQL> CREATE TABLE employee (
  2    id         INTEGER PRIMARY KEY,
  3    first_name VARCHAR2(10),
  4    last_name  VARCHAR2(10),
  5    addresses  nested_table_AddressType
  6  )
  7  NESTED TABLE
  8    addresses
  9  STORE AS
 10    nested_addresses;

Table created.

SQL>
SQL>
SQL> INSERT INTO employee VALUES (
  2    1'Steve', 'Brown',
  3    nested_table_AddressType(
  4      AddressType('2 Ave', 'City', 'MA', '12345'),
  5      AddressType('4 Ave', 'City', 'CA', '54321')
  6    )
  7  );

row created.

SQL>
SQL> select from employee;

ID FIRST_NAME LAST_NAME  ADDRESSES(STREET, CITY, STATE, ZIP)
--------------------------------------------------------------------------------------------------------
1  Steve      Brown      NESTED_TABLE_ADDRESSTYPE(ADDRESSTYPE('2 Ave', 'City', 'MA', '12345'), ADDRESSTYPE('4 Ave', 'City', 'CA', '54321'))


SQL>
SQL> drop table employee;

Table dropped.

SQL>
SQL>














26.9.Nested Table Column
26.9.1.Using a Nested Table Type to Define a Column in a Table
26.9.2.Getting Information on Nested Tables
26.9.3.Set the depth to 2 and describe a nested table
26.9.4.Populating a Nested Table with Elements
26.9.5.Selecting Nested Table Elements
26.9.6.Modifying Nested Table Elements
26.9.7.Update the first record in the nested table.
26.9.8.Delete one record in the nested table
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.