Skip to Main Content
  • Questions
  • Nested Tables Vs Relational Vs <Suggestion>

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Sumit.

Asked: June 11, 2007 - 1:41 pm UTC

Last updated: June 12, 2007 - 1:52 pm UTC

Version: 10.2.1.0

Viewed 1000+ times

You Asked

Hi Tom,

Need your expert advice and guidance on a very important aspect.
Actually we are designing one application which has one of the following requirements:
> There is a table consisting of some columns. Pertaning to a column in the table, it may have one or more than one values for a record. An analogy for this would be the information regarding an employee. Now there is a column for Phone number. A person may have one/two/three or more phones.
The count of this is not fixed.
Hence need to design a table that can hold such kind of data.

We thought of storing the same as a nested table (object type) in the table. But are not too sure about the limitations / problems with the same that we might encounter in the near future...

Another option is to break this table into two and link with a key value. But our application is such that the data in this table is going to be extremely large - to the order of millions of records per day.

Would request you to please help us in this regard, as it is very critical to us.

Thanking in advance and hoping for a bright guidance as always from you.

Best Regards,
Sumit.

and Tom said...

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:8135488196597

I would not encourage the use of either nested tables or varrays to persist (store on disk) data.

For starters, I want to know who has phone number 123-456-7890

if you "hide" phone number as a nested table/varray of a person - it becomes very cumbersome to query. Phone numbers stand alone as an entity in most cases, they should not be hidden.

I wrote in Expert one on one Oracle (in summary):

<quote>
Nested Tables Wrap-up
I do not use nested tables as a permanent storage mechanism myself, and this is for the following reasons:

o The overhead of the RAW(16) columns that are added. Both the parent and child table will have this extra column. The parent table will have an extra 16 byte raw for each nested table column it has. Since the parent table typically already has a primary key (DEPTNO in my examples) it would make sense to use this in the child tables, not a system generated key
o The overhead of the unique constraint on the parent table, when it already typically has a unique constraint.
o The nested table is not easily used by itself, without using unsupported constructs (NESTED_TABLE_GET_REFS). It can be unnested for queries but not mass updates.

I do use nested tables heavily as a programming construct and in views. This is where I believe they are in their element and in Chapter XX Using Object Relational Features we see how to exploit them in this fashion. As a storage mechanism I would much prefer creating the parent/child tables myself. After creating the parent/child tables ¿ we can in fact create a view that makes it appear as if we had a real nested table. That is, we can achieve all of the advantages of the nested table construct without incurring the overhead. Again in Chapter XX Using Object Relational Features we¿ll take a detailed look at how to accomplish this.

If you do use them as a storage mechanism, be sure to make the nested table an ORGANIZATION INDEX table to avoid the overhead of an index on the NESTED_TABLE_ID and the nested table itself. See the section above on IOTS for advice on setting them up with overflow segments and other options. If you do not use an IOT, make sure then to create an index on the NESTED_TABLE_ID column in the nested table to avoid full scanning it to find the child rows.
</quote>

So, my suggestion:

good old fashioned relational tables.

Rating

  (4 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

O-R or O-O is dead

Yang, June 12, 2007 - 3:08 am UTC

As far as I am concerned, the implementation of Object- Relational Database or Object-Oriented Database in "Real World" is really rare. I am just wondering that why Oracle spare efforts on catering for those "dead" techonologies? Or if I am worng, could you please share some story about O-R or O-O database implementation?

Thanks a lot..

Sumit Thapar, June 12, 2007 - 3:10 am UTC

Hi Tom,

Thanks a lot for your prompt response on the same.
Have one more question on this then. What are the situations in which we can use object types to get the maximum benefit out of them (and should we never use them in DB, only in PL/SQL ? )

Thanks in advance

Best Regards,
Sumit
Tom Kyte
June 12, 2007 - 10:08 am UTC

As stated, I use them in programming all of the time, they are very useful in pipelined functions, they are very useful in plsql programming.

They can be mapped to from various 3gls, so it gives a "richer way" to send data structures from clients to plsql.

can you provide an example

neil kodner, June 12, 2007 - 11:13 am UTC

<quote>They can be mapped to from various 3gls, so it gives a "richer way" to send data structures from clients to plsql.
</quote>

Do you have any examples? I've been wondering how to do this for a while; I'm not even sure what to search for-I'm just a caveman DBA :)

As far as object types and pipelined row functions, they're the greatest - I've turned many an U-G-L-Y query into a pipelined row function for big performance gains.
Tom Kyte
June 12, 2007 - 1:52 pm UTC

pro*c guides have examples for pro*c
jdbc guides have them for jdbc

and so on....

here:
http://docs.oracle.com/docs/cd/B19306_01/java.102/b14188/toc.htm
for java jpublisher - have the database generate a java class that maps to the database object type.

Useful and sincere

MIke Tölgyesi, November 19, 2019 - 1:52 pm UTC

TOM gave a straightforward answer to the question. Some Oracle constructs (ex. object-types, etc.) are cumbersome to use and present no real advantage.