Question

I generally know quite a lot about whole stuff on collections themselves, but I don't get one point. Why store collection (as nested tables and varrays) in the database?

I see that it is useful to have arrays, in general, in programming language, but I don't understand how they are useful when part of a table. Couldn't everything could be implemented as simple relations between two entities?

Why/where should I use nested tables or arrays as part of a table and what are benefits of them?

Was it helpful?

Solution

Oracle started support for objects in the database as part of a long discarded rebranding exercise. Oracle8 was positioned as an ORDBMS rather than just an RDBMS. Then Larry discovered the internet, they put Java in the database and discreeting re-re-brand Oracle8i as an RDBMS.

Nevertheless SQL types remain. They are a good thing. As you say, arrays are a brilliant programming device, very useful in PL/SQL. And in heritance and polymorphism allow us to build lovely APIs.

But, to your key point:

"I don't see why to store them in such way in database"

Exactly so. There are almost no good reasons to use SQL types in database table definitions. Theoretically they could be used to define domain types but the syntax is too clunky to make it work the effort. That goes double for defining columns as nested tables. That makes it hard to enforce normalisation and relational integrity.

I have come across a couple of very niche cases, but they weren't core database tables. Rather they were utilities such as log tables.

OTHER TIPS

though most of the table operations can be performed using joins but sometimes varrays and nested tables become very useful. one case where we used to do was, send a comma separated string to pl/sql from jdbc and then convert the string to a varray using a function, then use it for further operations in IN clause. at this point varrays become useful.

this link provides good explanations... http://www.indicthreads.com/9429/plsql-collections-associative-arrays-nested-tables-varray-collection-methods/

enjoy :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top