1 dbms_random.random [common method (random acquisition of a piece of data)]
Java code
Select * from (select t. * from T t order by dbms_random.random) where rownum <2;
2 internal function sys_guid ()
Java code
Select * from (select t. * from T t order by sys_guid () where rownum <(select count (1) from T );
Select * from (select t. * from T t order by sys_guid () where rownum <2;
3. Use sample to obtain a random result set
Java code
Select * from T sample (10) seed (10) where rownum <6;
Select * from T sample block (10) where rownum <6;
Note: When sys_guid () is used, the same record is sometimes obtained, that is, the result set of the previous query is the same, some of them are related to the operating system. Normally on windows platforms, the obtained data is random, while on linux and other platforms it is always the same data set. Some are said to be caused by sys_guid () function itself, that is, sys_guid () will generate a 16-byte globally unique identifier on the query. This identifier is composed of a host identifier and the thread identifier of the process or process on most platforms, that is to say, it is probably random, but it does not mean it must be.
Therefore, to ensure that the data read on different platforms is random, most of us use the sample function or DBMS_RANDOM package to obtain a random result set. The sample function is more commonly used, because the query scope is reduced during the query, the query speed is significantly improved when a large table is queried and the data to be extracted is not very small.
Author: "Getting to the ground"