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