NOT INSTANTIABLE Object Types : Type Inheritance « Object Oriented « Oracle PL/SQL Tutorial






You can mark an object type as NOT INSTANTIABLE, which prevents objects of that type from being created.

SQL> CREATE Or Replace TYPE ProductType AS OBJECT (
  2    id    NUMBER,
  3    make  VARCHAR2(15),
  4    model VARCHAR2(15)
  5  ) NOT FINAL NOT INSTANTIABLE;
  6  /

Type created.


SQL>
SQL> CREATE Or replace TYPE SubProduct1 UNDER ProductType (
  2    convertible CHAR(1)
  3  );
  4  /

Type created.

SQL> CREATE Or replace TYPE SubProduct2 UNDER ProductType (
  2    sidecar CHAR(1)
  3  );
  4  /

Type created.

SQL> CREATE TABLE product OF ProductType;

Table created.

SQL> CREATE TABLE cars OF SubProduct1;

Table created.

SQL> CREATE TABLE motorcycles OF SubProduct2;

Table created.

SQL>
SQL> INSERT INTO cars VALUES (
  2    SubProduct1(1, 'AA', 'MR2', 'Y')
  3  );

1 row created.

SQL>
SQL> INSERT INTO motorcycles VALUES (
  2    SubProduct2(1, 'BB', 'V-Rod', 'N')
  3  );

1 row created.

SQL> SELECT *
  2  FROM cars;

        ID MAKE            MODEL           C
---------- --------------- --------------- -
         1 AA              MR2             Y

SQL>
SQL> drop table product;

Table dropped.

SQL> drop table cars;

Table dropped.

SQL> drop table motorcycles;

Table dropped.

SQL>
SQL>
SQL>








32.5.Type Inheritance
32.5.1.Type Inheritance
32.5.2.The NOT FINAL clause indicates that object can be inherited from when defining another type.
32.5.3.NOT FINAL clause
32.5.4.Insert data into table with inheritecd columns
32.5.5.select from inherited object columns
32.5.6.NOT INSTANTIABLE Object Types
32.5.7.Query table with sub type column
32.5.8.Insert into table with sub type column