Search code examples
sqloracle-databasenested-table

How to add column to nested table in Oracle SQL


I have table with nested table, and I want to add another column to the nested table. Is it possible? If it is, what is the syntax? couldn't find it anywhere..

Consider this example:

CREATE TYPE address_t AS OBJECT (
   street  VARCHAR2(30),
   city    VARCHAR2(20),
   zip     NUMBER );
 
CREATE TYPE addresses_nested IS TABLE OF address_t;

CREATE TABLE customers (
   id NUMBER,
   address addresses_nested )
   NESTED TABLE address STORE AS customer_addresses;

It Creates the the table "customers" with nested table "addresses_nested": enter image description here

Can u give an example how to add column to "addresses_nested" if possible? Thank you


Solution

  • I if followed correctly, you want to add an attribute to the underlying type. If so, you can use the alter type statement:

    alter type address_t add attribute phone varchar2(12) cascade;