Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8923571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:09:38+00:00 2026-06-15T07:09:38+00:00

I have created the following in Oracle PSL/SQL: I have created a type Animal

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:09:40+00:00Added an answer on June 15, 2026 at 7:09 am

    “When creating the Animal table of type Animal, how do I create the
    nested table for “places lived”? when 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.

    create or replace type animal_t as object 
      ( name varchar2(10)
        , age number (3,0))
    not final;
    /
    
    create or replace type places_nt as table of varchar2(20)
    /
    
    create or replace type dog_t under animal_t
     ( residence_history places_nt)
    /
    
    create table animals of animal_t;
    

    To create a record for a goldfish we do this:

    insert into animals
      values (animal_t('BOB', 7))
    /
    

    To create a record for a dog we need to do this:

    insert into animals
      values (dog_t('FIDO', 12, places_nt('Balham', 'Tooting')))
    /
    

    This query will just select the generic columns:

    SQL> select * from animals
      2  /
    
    NAME              AGE
    ---------- ----------
    BOB                 7
    FIDO               12
    
    SQL>
    

    To gain sight of the details pertaining to dogs we need to cast the record to the relevant sub-type:

    SQL> select treat(value(a) as dog_t)
      2  from animals a
      3  where value(a) is of (dog_t)
      4  /
    
    TREAT(VALUE(A)ASDOG_T)(NAME, AGE, RESIDENCE_HISTORY)
    --------------------------------------------------------------------------------
    DOG_T('FIDO', 12, PLACES_NT('Balham', 'Tooting'))
    
    SQL>
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Oracle SQL query. Given a given name and surname, it
I have created the following class class Contact def initialize(id, name, phone) @id =
I have created a linked server in SQL Server 2005 to an Oracle DB.
I have the following sql being run on an Oracle 10g database: select /*+
Hi I have the following function created in Oracle. i will have to pass
I am new to oracle, I have created two tables using following queries, CREATE
I'm using SQL*Plus 9.2 on Oracle 10g enterprise. I have created some scripts that
I have a table like the following ID created sent type ----------------------------------------------------- 0001463583000051783 31-JUL-12
I am using Oracle 10g and I have the following stored procedure: CREATE OR
I have created following rule in the .htaccess file located at the root of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.