Provides you with an in-depth understanding of Oracle random number generation functions.

Source: Internet
Author: User

Oracle random number generation function can return a random number between 0 and 1. This function has good practical value. Let's take a look at the usage of Oracle random number generation function.

Oracle8 version 8.0 introduces the DBMS_RANDOM package and Oracle8i 8.1.6 introduces the new features of the DBMS_RANDOM package. However, the Oracle8i documentation does not provide a detailed description of its functions. Fortunately, a new DBMS_RANDOM packet function can return a random number between 0 and 1. The new Oracle random number generation function is:
◆ FUNCTION value return number;
◆ FUNCTION value (low in number, high in number) return number;
◆ FUNCTION normal return number;
◆ FUNCTION string (opt char, len NUMBER) RETURN VARCHAR2;

The first form of the VALUE function returns a random number greater than or equal to 0 and less than 1; the second form returns a random number greater than or equal to LOW, less than HIGH. The following is an example of its usage:

 
 
  1. SQL> select dbms_random.value, dbms_random.value(55,100) from dual;   
  2. VALUE            DBMS_RANDOM.VALUE(55,100)   
  3. --------------- -----------------------------   
  4. .782821936       79.6367038    

The NORMAL function returns a group of numbers that follow the 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. In fact, this is what you see in Listing 1.

Finally, it is the STRING function. It returns a random string of 60 characters. The OPT parameter can be any single character in the value displayed in Listing 2.

The Oracle random number generation function and DBMS_RANDOM package files are included in SQLPlus:

 
 
  1. select text   from all_source    
  2.        where name = 'DBMS_RANDOM'    
  3.        and type = 'PACKAGE' order by line;   

Use of oracle custom functions

Oracle TRIM function syntax

Oracle date functions

Introduction to Oracle System Variable Functions

Syntax for creating an Oracle package

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.