Random Number of oracle (result set)

Source: Internet
Author: User

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"
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.