Subject | Re: random row select |
---|---|
Author | Adam |
Post date | 2006-10-25T04:06:20Z |
--- In firebird-support@yahoogroups.com, "Yosvany Llerena RodrÃguez"
<yosvanyllr@...> wrote:
number. If your source table is fixed, then the procedure is pretty
simple.
CREATE PROCEDURE FOO
RETURNS
(
BAR INTEGER
)
AS
DECLARE VARIABLE RND INTEGER;
BEGIN
RND = RAND(100);
FOR SELECT BAR
FROM MYTABLE
WHERE ID = :RND
INTO :BAR
DO
BEGIN
SUSPEND;
END
END
^
SELECT BAR
FROM FOO;
Note that a lot of random number generators are based on the internal
clock, and so if you include a call to the SP in a tight loop you may
get the same row several times.
Adam
<yosvanyllr@...> wrote:
>You will need to find/write a UDF function to generate a random
> Hi all.
>
> I'm tryin to create and stored procedure to select a random row from a
> table, of curse in where clasusle i have an integer field. I means
> random between 1 and the max of this field.
>
number. If your source table is fixed, then the procedure is pretty
simple.
CREATE PROCEDURE FOO
RETURNS
(
BAR INTEGER
)
AS
DECLARE VARIABLE RND INTEGER;
BEGIN
RND = RAND(100);
FOR SELECT BAR
FROM MYTABLE
WHERE ID = :RND
INTO :BAR
DO
BEGIN
SUSPEND;
END
END
^
SELECT BAR
FROM FOO;
Note that a lot of random number generators are based on the internal
clock, and so if you include a call to the SP in a tight loop you may
get the same row several times.
Adam