Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL question

Re: SQL question

From: DA Morgan <damorgan_at_exesolutions.com>
Date: Mon, 10 Feb 2003 09:13:52 -0800
Message-ID: <3E47DDD0.DBDFC120@exesolutions.com>


"Jason D." wrote:

> I have a table called EMPLOYEES and I have a select statement with which I
> retrieve records that fit certain criteria.
>
> Is there a way to tweak the select to return only ONE of these records and
> preferably a random one?
>
> I want to use this select in an automated test case and want to pass only
> one set of values at a time.

WHERE rownum = 1

And while it will be the first record ... it will also be random as the record that is the first record, from a heap table, is not necessarily and different from any other record.

If you truly want random then you will probably want to use an in-line view and do something like this:

i := randomly generated number (look at the DBMS_RANDOM built-in package)

SELECT *
FROM (
   SELECT rownum RN_ALIAS, field1, field2, field3    FROM table
   WHERE rownum <= i)
WHERE RN_ALIAS = i;

Daniel Morgan Received on Mon Feb 10 2003 - 11:13:52 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US