Oracle 5.0 Reference Manual page 933

Table of Contents

Advertisement

+------+------------------+
|
1 | 0.90576975597606 |
|
2 | 0.37307905813035 |
|
3 | 0.14808605345719 |
+------+------------------+
3 rows in set (0.01 sec)
The effect of using a nonconstant argument is undefined. As of MySQL 5.0.13, nonconstant
arguments are not permitted.
To obtain a random integer
[910]
– i)). For example, to obtain a random integer in the range the range
(j
could use the following statement:
SELECT FLOOR(7 + (RAND() * 5));
[912]
in a
RAND()
WHERE
You cannot use a column with
would evaluate the column multiple times. However, you can retrieve rows in random order like this:
mysql>
SELECT * FROM tbl_name ORDER BY RAND();
ORDER BY RAND()
rows:
mysql>
SELECT * FROM table1, table2 WHERE a=b AND c<d
[912]
is not meant to be a perfect random generator. It is a fast way to generate random
RAND()
numbers on demand that is portable between platforms for the same MySQL version.
[913],
ROUND(X)
ROUND(X,D)
Rounds the argument
defaults to 0 if not specified.
X.
D
value
to become zero.
X
mysql>
SELECT ROUND(-1.23);
-> -1
mysql>
SELECT ROUND(-1.58);
-> -2
mysql>
SELECT ROUND(1.58);
-> 2
mysql>
SELECT ROUND(1.298, 1);
-> 1.3
mysql>
SELECT ROUND(1.298, 0);
-> 1
mysql>
SELECT ROUND(23.298, -1);
-> 20
The return type is the same type as that of the first argument (assuming that it is integer, double, or
decimal). This means that for an integer argument, the result is an integer (no decimal places):
mysql>
SELECT ROUND(150.000,2), ROUND(150,2);
+------------------+--------------+
| ROUND(150.000,2) | ROUND(150,2) |
+------------------+--------------+
|
150.00 |
+------------------+--------------+
Before MySQL 5.0.3, the behavior of
integers depends on the C library implementation. Different implementations round to the nearest
even number, always up, always down, or always toward zero. If you need one kind of rounding, you
should use a well-defined function such as
Mathematical Functions
in the range
R
i
clause is re-evaluated every time the
[912]
RAND()
combined with
is useful for selecting a random sample from a set of
LIMIT
[913]
to
decimal places. The rounding algorithm depends on the data type of
X
D
can be negative to cause
D
150 |
ROUND()
TRUNCATE()
913
<=
< j, use the expression
R
WHERE
values in an
ORDER BY
->
ORDER BY RAND() LIMIT 1000;
digits left of the decimal point of the
D
[913]
when the argument is halfway between two
[914]
or
FLOOR()
FLOOR(i + RAND() *
<=
< 12, you
7
R
is executed.
clause, because
ORDER BY
[910]
instead.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents