I have created the following in Oracle PSL/SQL:
I have created a type Animal.
This has the attributes: Name, Age
I have created the type Dog. This inherits from type Animal
The only extra field in Dogis a nested table of references of place lived. I want to store all instances of Dogin the Animal table.
This is the bit I am confused about: When creating the Animal table of type Animal, how do I create the nested table for places lived? There is no field in Animal for this, only in Dog.
This is the mystery of inheritance. A table built from the type ANIMAL actually has columns to support the attributes of its sub-types. However, they are only accessible when we explicitly use the DOG sub-type.
Here is your data structure.
To create a record for a goldfish we do this:
To create a record for a dog we need to do this:
This query will just select the generic columns:
To gain sight of the details pertaining to dogs we need to cast the record to the relevant sub-type:
There is an entire book in the Oracle documentation devoted to its Object-Relational features. Find out more.
Note: I have used an object table here simply because it is easy to illustrate how nested tables work. I do not recommend using types for data storage: OO is a programming paradigm and should only be used for writing programs. Data should always be persisted in relational structures.