Reputation: 819
I'm very new to SQL and would like to know how to get some data from a table and place it into an array. If I have this:
SELECT SeatNo FROM SEATING_PLAN
WHERE Block = 1;
SeatNo and Block are INT.
What sort of array should I use to place all of the seat numbers that match into the array, and what sort of loop is best for this?
Thanks in advance
Upvotes: 0
Views: 100
Reputation: 1748
In PL/SQL you have 2 types of arrays, associative arrays and variant arrays. There is another type of collection in PL/SQL called Nested Tables. This profussion makes PL/SQL obscure as the three are treated similarly for some operations and completely different for other.
http://docs.oracle.com/cd/B12037_01/appdev.101/b10807/05_colls.htm
If you want to store scalar type collections, I recommend you to use associative arrays:
DECLARE
TYPE t_SeatNo is TABLE OF SEATING_PLAN.SeatNo%TYPE INDEX BY BINARY_INTEGER;
seats t_SeatNo;
BEGIN
SELECT SeatNo
BULK COLLECT INTO seats
FROM SEATING_PLAN
WHERE Block = 1;
-- Do what you need with the data
END;
Upvotes: 1