
Os vencedores foram o josé e o Rui, o script utilizado para sortear foi o seguinte
declare
type tt_varchar2 is table of varchar2(50) index by binary_integer;
Candidatos tt_varchar2;
L_sorteado Number;
-------------
procedure add_nome(I_nome varchar2, I_quantidade number)
is
begin
For i in 1..I_quantidade
loop
Candidatos(NVL(Candidatos.last,0)+1) := I_nome;
End loop;
end;
begin
add_nome('João ------', 4);
add_nome('José ------', 10);
add_nome('Miguel ------', 3);
add_nome('Orlando ----------', 1);
add_nome('Ricardo ------', 2);
add_nome('Rui ------', 5);
for i in 1..Candidatos.count
loop
dbms_output.put_line('('||i||')->'||Candidatos(i));
End Loop;
-------------------------------------------
SELECT reverse(to_char(to_number(to_char(systimestamp, 'FF6'))))
into L_sorteado
FROM dual;
dbms_output.put_line('milisegudos ->'||L_sorteado);
L_sorteado := mod(L_sorteado,Candidatos.count)+1 ;
dbms_output.put_line(' o sorteado foi o ('||L_sorteado||') ->'||Candidatos(L_sorteado));
End;
Toma lá muito mais simples.
ResponderEliminarDECLARE
TYPE tt_varchar2 IS TABLE OF VARCHAR2 (50)
INDEX BY BINARY_INTEGER;
candidatos tt_varchar2;
l_sorteado NUMBER;
-------------
PROCEDURE add_nome (
i_nome VARCHAR2,
i_quantidade NUMBER
)
IS
BEGIN
FOR i IN 1 .. i_quantidade
LOOP
candidatos (NVL (candidatos.LAST, 0) + 1) := i_nome;
END LOOP;
END;
BEGIN
add_nome ('aaaa bbbbb', 4);
add_nome ('cccc ddddd', 10);
FOR i IN 1 .. candidatos.COUNT
LOOP
DBMS_OUTPUT.put_line ('(' || i || ')->' || candidatos (i));
END LOOP;
/*----------------------------------------------------------------------------------------------
-- From: Oracle 10gR2 Documentation
-- http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_random.htm
-- DBMS_RANDOM can be explicitly initialized, but does not need to be initialized before calling
-- the random number generator. It will automatically initialize with the date, userid, and
-- process id if no explicit initialization is performed.
----------------------------------------------------------------------------------------------*/
l_sorteado := TRUNC (DBMS_RANDOM.VALUE (1, candidatos.COUNT ()));
DBMS_OUTPUT.put_line (' o sorteado foi o (' || l_sorteado || ') ->' || candidatos (l_sorteado) );
END;