The use of the Dbms_random.value function trunc () function

Source: Internet
Author: User
Tags numeric value truncated

I.use of the Oracle Trunc () function
TRUNC (for dates)
Precision to day Select Trunc (sysdate, ' DD ') from dual result is: 2010-9-17
Accurate to Month select Trunc (sysdate, ' mm ') from dual result: 2010-9-1
Accurate to Year select Trunc (sysdate, ' yy ') from dual result: 2010-1-1

TRUNC (for number)
The TRUNC function returns the processed value, and its working mechanism is very similar to the round function, except that the function does not make the corresponding rounding selection processing of the specified fractional number before or after it, and it is truncated altogether.
Its specific syntax format is as follows
TRUNC (number, [decimals])
which
Number to be intercepted and processed
Decimals indicates the number of digits after the decimal point to be retained. Optional, ignore it to truncate all the decimal parts
Here's how this function is used:
Select TRUNC (899.985,2) from dual results are: 899.98
Select TRUNC (899.985) from dual results are: 899
Select TRUNC (899.985) from dual results are: 800
Note: The second parameter can be a negative number, which means that the portion of the digits to the left of the decimal point is truncated to 0.

Second,dbms_random.value function
Dbms_random is a package that can generate random numbers or strings. This package has several functions such as initialize (), seed (), terminate (), value (), Normal (), random (), string (), but value () is the most common.
The use of value () generally has two types,
The first function value return number;
This usage has no parameters and returns a numeric value with a 38-bit precision ranging from 0.0 to 1.0, but not 1.0, as follows:
Select Dbms_random.value () from dual results: 0.265729284748573

The second value has two parameters, the first is the lower limit, the second is the upper limit, and the number between the lower bound and the upper bound is generated, but not the upper limit, as follows:
Select Dbms_random.value (1,7) from dual results are: 3.38380283953849

The two combine together with Trunc (Dbms_random.value (1,7)) which is randomly obtained as an integer X, 1<=x<7, as follows:
Select Trunc (Dbms_random.value (1, 7)) from dual result: 3

The use of the Dbms_random.value function trunc () function

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.