Tuesday, November 5, 2013

Oracle TRUNC Function

TRUNC(number) function can take two arguments.
TRUNC(param1,param2)

Here the function will return param1 truncated by param2 decimal places.










If param2 is omitted the function will return param1 truncated by 0 decimal places.










param2 can be negative as well. This will truncate the digits left of the decimal point.










The general behavior of TRUNC function is as below.

TRUNC(n,m) is

TRUNC(n,m) = TRUNC(n * 10 ^ m) * 10 ^ (-m)

In the above case, where m = -2

TRUNC(123.456,-2) = TRUNC(123.456 * 10 ^ (-2)) * 10 ^ (2)
                                  = TRUNC(1.23456) * 100
                                  = 1 * 100
                                  = 100

This function can take any numeric data type as an argument or any non-numeric data type that can be implicitly converted to a numeric data type.










No comments:

Post a Comment