Re: How to generate specified Random
From: Arjan van Bentem <avbentem_at_DONT-YOU-DAREdds.nl>
Date: 1998/08/14
Message-ID: <6r1p5u$egk$1_at_newton.a2000.nl>#1/1
)
and rownum < 2;
Date: 1998/08/14
Message-ID: <6r1p5u$egk$1_at_newton.a2000.nl>#1/1
I guess you really want a random pick. First of all, you'd need a random
generator. See
http://www.oracle.com/st/products/features/free_plsql_utilities.html to get
the function Rand.
Next:
select name
from doctors
where rowid in
( select rowid
from doctors where specialism = 'Cancer' order by Rand
)
and rownum < 2;
Bad thing is that all doctors having specialism Cancer are selected in the subquery, even though only one is needed. If you're temped to skip the subselect, note that you can not use
where rownum = xxx
(unless xxx = 1) as rownum is only incremented when a row is selected. So, using = instead of < will result in no rows at all.
Arjan. Received on Fri Aug 14 1998 - 00:00:00 CEST