Home » SQL & PL/SQL » SQL & PL/SQL » exact definition of Collection
exact definition of Collection [message #601565] Fri, 22 November 2013 04:17 Go to next message
ramya29p
Messages: 146
Registered: November 2007
Location: Chennai
Senior Member
Hi,
In Internet i have read the collection Definition as
A collection is an ordered group of elements, all of the same type. It is a general concept that encompasses lists, arrays, and other datatypes used in classic programming algorithms. Each element is addressed by a unique subscript.

But when we define a collection with rowtype%tablename for example
Type type1 table of emp%rowtype;
,
how can we say that collection is a group of elements of same type. i'm confused with the statement.

could anyone please help me out?
Re: exact definition of Collection [message #601568 is a reply to message #601565] Fri, 22 November 2013 04:27 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
ramya29p wrote on Fri, 22 November 2013 15:47
Hi,
In Internet i have read the collection Definition as
A collection is an ordered group of elements, all of the same type. It is a general concept that encompasses lists, arrays, and other datatypes used in classic programming algorithms. Each element is addressed by a unique subscript.

But when we define a collection with rowtype%tablename for example
Type type1 table of emp%rowtype;
,
how can we say that collection is a group of elements of same type. i'm confused with the statement.


So what's the issue in understanding the definition, it is perfect. It has to be of same type in each group of elements. When you use %ROWTYPE, you have multiple ordered groups of elements, each group MUST have elements of same type. Don't get confused between an entire collection and each group of elements.
Re: exact definition of Collection [message #601571 is a reply to message #601568] Fri, 22 November 2013 04:45 Go to previous messageGo to next message
ramya29p
Messages: 146
Registered: November 2007
Location: Chennai
Senior Member
Thanks for your reply.
Re: exact definition of Collection [message #601573 is a reply to message #601568] Fri, 22 November 2013 05:11 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
Lalit Kumar B wrote on Fri, 22 November 2013 11:27
So what's the issue in understanding the definition, it is perfect.

No it is not perfect, as it does not specify in what context the term ordered has been used. The quoted definition says: "A collection is an ordered group of elements, all of the same type."
If we're talking about stored collections such as nested table and varrays then the term order makes sense only for varrays (order is not necessarily conserved for nested tables upon store/read into/from database)

Also, an associative array is a key-value mapping based on a hash function, so again, one has to be clear what the term order means in this context.

for the OP:

http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/composites.htm#LNPLS005
Quote:

A composite data type stores values that have internal components. You can pass entire composite variables to subprograms as parameters, and you can access internal components of composite variables individually. Internal components can be either scalar or composite. You can use scalar components wherever you can use scalar variables. PL/SQL lets you define two kinds of composite data types, collection and record. You can use composite components wherever you can use composite variables of the same type.

In a collection, the internal components always have the same data type, and are called elements
. . .

[Updated on: Fri, 22 November 2013 05:17]

Report message to a moderator

Re: exact definition of Collection [message #601576 is a reply to message #601573] Fri, 22 November 2013 05:31 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
dariyoosh wrote on Fri, 22 November 2013 16:41
Lalit Kumar B wrote on Fri, 22 November 2013 11:27
So what's the issue in understanding the definition, it is perfect.

No it is not perfect, as it does not specify in what context the term ordered has been used. The quoted definition says: "A collection is an ordered group of elements, all of the same type."


OP is confused that the multiple groups in a collection are of similar datatype. Which is not true, each group's elements needs to be of same datatype. The definition by which OP got confused is a general statement about collections which are widely used. To understand firmly, OP needs to do further reading in depth. PL/SQL Collections and Records

The doc says, "A collection is an ordered group of elements, all of the same type. It is a general concept that encompasses lists, arrays, and other familiar datatypes. Each element has a unique subscript that determines its position in the collection."

And then, "In a collection, the internal components always have the same data type, and are called elements."

A short definition of collections will not completely answer OP's confusion, OP must go through the entire concept explained in the manual. And, as a general concept, I still believe the definition is good.

Re: exact definition of Collection [message #601577 is a reply to message #601576] Fri, 22 November 2013 05:43 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
Lalit Kumar B wrote on Fri, 22 November 2013 12:31

The definition by which OP got confused is a general statement about collections which are widely used.

Used by whom? it's not the number of people using a definition, which makes it correct, IMHO

Lalit Kumar B wrote on Fri, 22 November 2013 12:31
A short definition of collections will not completely answer OP's confusion

And you believe that by approving that flawed concept about ordering you're helping him to understand?

Lalit Kumar B wrote on Fri, 22 November 2013 12:31

OP must go through the entire concept explained in the manual. And, as a general concept, I still believe the definition is good.

Then both of you may want to have a look at the link I posted.

[Updated on: Fri, 22 November 2013 05:49]

Report message to a moderator

Re: exact definition of Collection [message #601580 is a reply to message #601577] Fri, 22 November 2013 06:33 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
dariyoosh wrote on Fri, 22 November 2013 17:13
Then both of you may want to have a look at the link I posted.


Thanks for the suggestion. You have gone beyond the original post.

The question was,

ramya29p wrote on Fri, 22 November 2013 15:47
But when we define a collection with rowtype%tablename...
how can we say that collection is a group of elements of same type. i'm confused with the statement.


And the simple answer was,

Lalit Kumar B wrote on Fri, 22 November 2013 15:57
It has to be of same type in each group of elements. When you use %ROWTYPE, you have multiple ordered groups of elements, each group MUST have elements of same type. Don't get confused between an entire collection and each group of elements.


OP did not mention anywhere about his confusion with the term "ordered".
Re: exact definition of Collection [message #601581 is a reply to message #601580] Fri, 22 November 2013 06:35 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
/forum/fa/1597/0/
Re: exact definition of Collection [message #601592 is a reply to message #601576] Fri, 22 November 2013 08:58 Go to previous message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Lalit Kumar B wrote on Fri, 22 November 2013 06:31
A short definition of collections will not completely answer OP's confusion, OP must go through the entire concept explained in the manual. And, as a general concept, I still believe the definition is good.


What is in that definition that doesn't answer question completely? It clearly says "A collection is an ordered group of elements, all of the same type". OP created collection type as:

Type type1 table of emp%rowtype;


What emp%rowtype means? It means RECORD. So type type1 is an ordered group of records. All elements in that collection have same type - record type. And not just any record but record with attributes same as in emp table. Why ordered? because each element within connection is indexed and NEXT and PRIOR honor that order.

SY.

[Updated on: Fri, 22 November 2013 08:59]

Report message to a moderator

Previous Topic: how to ignore year from date
Next Topic: "%s: invalid identifier" during Over(Partition by..)
Goto Forum:
  


Current Time: Fri Apr 26 22:07:18 CDT 2024