Oracle Fetch random Number

Source: Internet
Author: User

1, randomly fetching records from the tableSelect *  from(Select *  fromStaffOrder  bydbms_random.random)whereRowNum< 4To randomly fetch 3 records from the staff table2, generating random numbersSELECTDbms_random. RANDOM fromDUAL; produce a random number of arbitrary sizeSELECT ABS(MOD (Dbms_random. RANDOM, -)) fromDUAL; Generate a random number within 100SELECTTRUNC ( -+ the*Dbms_random.value) fromdual; Generates a random number between 100~1000SELECTDbms_random.value fromdual; Generates a random number between 0~1SELECTDbms_random.value (Ten, -) fromdual; Generates a random number between 10~20SELECTDbms_random.normal fromdual; The normal function returns a set of numbers that obey a normal distribution. This normal distribution has a standard deviation of 1 and a expected value of 0. The value returned by this function has a%is between-1 and+Between 1 and the%Between-2 and+Between 2 and About%Between-3 and+between 3. 3, generating a random stringSelectDbms_random.string ('P', -) fromdual; The first parameter P represents printable, where the string is made up of any printable character and the second parameter represents the return string length4The ceil (n) function returns the smallest integer greater than or equal to N. Dbms_random. VALUE () is randomly generated (0,1) between the numbers. To generate a two-bit random number, you can dbms_random. VALUE ()* -, this produces (0, -), when a random number is generated (0,Ten), just add 10 to ensure that the number is two. Oracle's PL/SQL provides several ways to generate random numbers and random strings, listed below:1Decimal0 ~ 1)     SelectDbms_random.value fromDual2, a decimal number within the specified range (0 ~  - )     SelectDbms_random.value (0, -) fromDual3, an integer within the specified range (0 ~  - )     SelectTrunc (Dbms_random.value (0, -)) fromDual4, a random number string of length 20SelectSubstrcast(Dbms_random.value as varchar2( -)),3, -) fromDual5, random number of normal distributionSelectDbms_random.normal fromDual6, random stringSelectDbms_random.string (opt, length) fromdual opt values are as follows:'u','U': Uppercase Letters'L','L': Lowercase Letters'a','A': Large, lowercase letters'x','X': Numbers, uppercase letters'P','P': Printable characters7, Random dateSelectTo_date (2454084+TRUNC (Dbms_random. VALUE (0,365)),'J') fromdual The base of the specified date by the following statementSelectTo_char (Sysdate,'J') fromDual8, generate GUIDsSelectSys_guid () fromDual--Create a custom function with a delimiter (-) GUIDCreate or Replace functionMy_guidreturn varchar2 isGUIDvarchar( $); Temp varchar( +);begin    Temp:=Sys_guid (); GUID:=SubstrTemp,1,8)|| '-'         ||SubstrTemp,9,4)|| '-'         ||SubstrTemp, -,4)|| '-'         ||SubstrTemp, -,4)|| '-'         ||SubstrTemp, +, A); returnGUID;End;

Oracle Fetch random Number

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.