Saturday, May 5, 2018

Using Trunc Function with Numbers in PLSQL

https://randomsrsolutions.blogspot.com/2018/05/using-trunc-function-with-numbers-in.html

The TRUNC function Truncates the Column, Expression or Value to n Decimal Places.
The TRUNC Function Works with arguments similar to those of the Round Function. If the Second argument is 0 or is missing , the value is truncated to Zero decimal places. If the second argument is 2, the value is truncated to two decimal places. Conversely, if the second argument is -2 the value is truncated to two decimal places to the left.
Like the Round Function, the TRUNC function can be used with Date functions

select
Trunc(5.9283),
Trunc(5.9283,0),
Trunc(5.9283,1),
Trunc(5.9283,2),
Trunc(5.9283,3)
from dual;

Trunc(5.9283)    Trunc(5.9283,0)    Trunc(5.9283,1)    Trunc(5.9283,2)    Trunc(5.9283,3)
                    5                            5                         5.9                       5.92                      5.928


select
Trunc(3.5397),
Trunc(3.5397,0),
Trunc(3.5397,1),
Trunc(3.5397,2),
Trunc(3.5397,3)
from dual;

Trunc(3.5397)    Trunc(3.5397,0)    Trunc(3.5397,1)    Trunc(3.5397,2)    Trunc(3.5397,3)
                     3                           3                         3.5                        3.53                     3.539

-----------------------------------------------------------------------------------------------

Trunc with -ve Decimal Request

select
Trunc(5675.9283,-1),
Trunc(5675.9283,-2),
Trunc(5675.9283,-3),
Trunc(5675.9283,-4)
from dual;

Trunc(5675.9283,-1)    Trunc(5675.9283,-2)    Trunc(5675.9283,-3)    Trunc(5675.9283,-4)  
                          5670                            5600                             5000                                   0

No comments:

Post a Comment

XLA to GL Link

  https://plsqlquery.blogspot.com/2025/12/xla-to-gl-link.html SELECT             acr.cash_receipt_id,             acr.receipt_number,       ...