Randomly fetching records from Oracle tables, generating random numbers and random strings ____oracle

Source: Internet
Author: User

1, take the record from the table randomly

SELECT * FROM (SELECT * to Staff ORDER by Dbms_random.random) indicates that 3 records are randomly taken from the staff table

Where RowNum < 4

2. Produce random number

SELECT Dbms_random. RANDOM from DUAL;

Produces a random number of any size

SELECT ABS (MOD (dbms_random). random,100)) from DUAL;

Produces a random number within 100.

SELECT TRUNC (100+900*dbms_random.value) from dual;

Produces a random number between 100~1000.

SELECT Dbms_random.value from dual;

Produces a random number between 0~1.

SELECT Dbms_random.value (10,20) from dual;

Produces a random number between 10~20.

SELECT dbms_random.normal from dual;

The normal function returns the number of groups that are subject to a normal distribution. The standard deviation of this normal distribution is 1 and the expected value is 0. 68% of the values returned by this function are between 1 and +1, 95% between-2 and +2, and 99% between 3 and +3.

3. Generate Random string

SELECT dbms_random.string from dual;

Returns a random string of up to 60 characters in length. (not tested successfully)

Select Dbms_random.string (' P ', m) from dual;

The first argument P represents printable, that is, the string is composed of any printable character
The second parameter indicates the length of the return string

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.