okay, I am beating myself up over this. I am need to load a array in people last name stored in a table. Then sort the last names and print them out in alphabetical order. This must be done using the bubble sort algorithm.
here is what I have so far
CREATE OR REPLACE PROCEDURE TEAM_TABLE_SORT AS
TYPE player_Name_type IS TABLE OF databasename.team.player%type
INDEX BY PLS_INTEGER ;
player_name player_Name_type;
i integer := 1;
temp integer;
BEGIN
FOR player_names IN (SELECT * FROM marshall.team )
LOOP
player_name(i) := player_names.player;
DBMS_OUTPUT.PUT_LINE(i|| ' - ' ||chr(9) || player_name(i) ) ;
i := i + 1 ;
END LOOP
All this really does is print out the names. I cannot get it to sort. I am not try thing this
TYPE player_Name_type IS TABLE OF %type INDEX BY varchar2(20) ;
aux player_Name_type;
i integer := 1;
v_current is table of aux
swapped BOOLEAN := TRUE;
BEGIN
FOR aux IN (SELECT * FROM )
LOOP
DBMS_OUTPUT.PUT_LINE(i|| ' - ' ||chr(9) || aux.player);
i := i + 1 ;
END LOOP;
v_current := aux.first;
WHILE(swapped)
LOOP
swapped := FALSE;
FOR I IN 1..(aux.count-2) LOOP
IF aux(i) > aux(I+1) THEN
v_current := aux(i+1);
aux(I+1) := aux(i);
aux(i) := v_current;
END IF;
swapped := TRUE;
END LOOP;
END LOOP;
FOR aux IN (SELECT * FROM LOOP
DBMS_OUTPUT.PUT_LINE(i|| ' - ' ||chr(9) ||aux.player);
i := i + 1 ;
END LOOP;
This should be what you are looking for. Note that it is better to type the variables/collections off of the tables like you have in your example. I just used generic versions since I don’t have your tables to work with. If you don’t understand how this is working, feel free to ask. I am guessing this is homework (who else would bubble sort in Oracle), so the point of the assignment is for you to understand it, not just to get it right. 🙂