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 Select question

Re: SQL Select question

From: Jim Kennedy <kennedy-down_with_spammers_at_attbi.com>
Date: Tue, 11 Feb 2003 01:46:25 GMT
Message-ID: <RBY1a.68134$HN5.248799@rwcrnsc51.ops.asp.att.net>


It doesn't matter if it is indexed that is irrelevant. If you don't order it then the results of what is first are unspecified(it could be anything). It MAY be a particular record each time, but since you didn't order the set then any record that id first is the one Oracle chose (and it could choose differently from execution to execution). The rownum=1 is to limit the set to whatever first record Oracle chose to get you.(you said you only wanted 1 record)

If you want to get really fancy and have it return a "random" row then you could do something like

select * from (select rownum,other columns .... from mytable where ... your where clause) where rownum=dbms_random..... or
select * from (select rownum,other columns .... from mytable where ... your where clause) where
mod(rownum,to_char(sysdate,'sssss'))=0;
 (or use minutes or hours instead of seconds)

Jim

--
Replace part of the email address: kennedy-down_with_spammers_at_attbi.com
with family.  Remove the negative part, keep the minus sign.  You can figure
it out.
"Jason D." <noonereally_at_vz.net> wrote in message
news:b28nv4$19o1mj$1_at_ID-157477.news.dfncis.de...

> Actually it is indexed and assigning a row num wouldn't really make the
> selection random, I will be probably be getting the same record for the
same
> parameters.
>
> "Jim Kennedy" <kennedy-down_with_spammers_at_attbi.com> wrote in message
> news:8aQ1a.62560$be.48274_at_rwcrnsc53...
> > If the set isn't ordered then just take the "first one" add rownum=1 to
> the
> > select.
> > Jim
> >
> > --
> > Replace part of the email address: kennedy-down_with_spammers_at_attbi.com
> > with family. Remove the negative part, keep the minus sign. You can
> figure
> > it out.
> > "Jason D." <noonereally_at_vz.net> wrote in message
> > news:b28iiv$19tf3t$1_at_ID-157477.news.dfncis.de...
> > > I have a table called EMPLOYEES and I have a select statement with
which
> I
> > > retrieve a certain amount of 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.
> > >
> > >
> >
> >
>
>
Received on Mon Feb 10 2003 - 19:46:25 CST

Original text of this message

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