Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Data from a table into an array

Status
Not open for further replies.

campbere

Technical User
Oct 10, 2000
146
0
0
US
I would like to select distinct titles from a table that has multiple columns into an array. Is this possible? If so how is it done?


Thanks
 
By "array" I assume you are referring to a PL/SQL table. In this case, I would define a cursor to select the distinct titles, then loop through the cursor to load the values into the PL/SQL table.

CURSOR title_cursor IS SELECT DISTINCT title FROM my_table;

TYPE ttable IS TABLE OF my_table.title%TYPE INDEX BY BINARY_INTEGER;
title_table TTABLE;

BEGIN

FOR t IN title_cursor LOOP
title_table(title_cursor%ROWCOUNT) := t.title;
END LOOP;
END;
 
Actually I am trying to avoid creating a table. This is part of a vb 6.0 application. I have a table that I would like to select one column of information into an array, not a PL/SQL table. After I insert the distinct titles into the array I want to the use the array in a for loop to take each distinct title and run in through a list of conditions, and then go to the next distinct title, until the end is reached.

I am not sure that a cursor is right for this, but then again I don't know much about cursors.
 
I feel what Carp says is right.

Though Cursors are discouraged but this seems a perfect candidate for use of cursors. If its a really huge table then may be some other way needs to be foud out because in such a case cursor would make it slow.

Regards
Prosenjit
 
campbere,

What's the structure of your table?
Mike
michael.j.lacey@ntlworld.com
 
I solved the problem be selecting the titles into a result set.

Thanks everyone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top