From the course: Oracle Database 12c: Basic SQL

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using TRUNC

Using TRUNC - Oracle Database Tutorial

From the course: Oracle Database 12c: Basic SQL

Start my 1-month free trial

Using TRUNC

- Similarly to round, another SQL function that allows us to deal with trailing digits following a decimal point is the trunk function. Trunk, unlike round, actually chops off numbers or digits following a decimal point, instead of rounding them up. Let's see it in action. We'll start by selecting a constant static value of 999.98765 from dual. Selecting the value as is will return the value as is. However, adding the trunk function, specifying the number inside brackets, comma and how many digits I want to remain after my decimal point, let's start with three. Running the query again will change the output to 999.987 as the trunk function left me with three digits following my decimal point. The rest was chopped off. Specifying one will modify my output to one digit following the decimal point. And specifying zero will get rid of all digits following the decimal point. Note that trunk, unlike round, will not round up or down any values. And of course, instead of specifying a constant…

Contents