Skip to content
Related Articles

Related Articles

PLSQL | TRUNC Function
  • Last Updated : 01 Nov, 2019

The TRUNC function is an inbuilt function in PLSQL which is used to return a number truncated to a particular number of decimal places.

Syntax:

TRUNC( number, decimal_places )

Parameters Used:
This function accepts two parameters which are illustrated below:-

  • number – This is the input number which is going to be truncated to a certain number.
  • decimal_places – This is also a input number which specifies that up to what number after decimal point should be the output of this function.

Return Value:
This function returns a numeric value truncated to a particular number of decimal places.

Supported Versions of Oracle/PLSQL:



  1. Oracle 12c
  2. Oracle 11g
  3. Oracle 10g
  4. Oracle 9i
  5. Oracle 8i

Let’s see some examples which illustrate the TRUNC function:

Example-1:

DECLARE 
   Test_Number number := 5.5;
   
BEGIN 
   dbms_output.put_line(TRUNC(Test_Number number)); 
   
END;  

Output:

5

In the above example, the truncated value of 5.5 is 5

Example-2:

DECLARE 
   Test_Number number1 := 5;
   Test_Number number2 := 0;
   
BEGIN 
   dbms_output.put_line(TRUNC(Test_Number number1, 
                              Test_Number number2)); 
   
END;  

Output:

5

In the above example, the truncated value of (5, 0) is 5 because 5 is not having any decimal point and hence it returns 5 as the output.

Example-3:

DECLARE 
   Test_Number number1 := 15.3123;
   Test_Number number2 := 2;
   
BEGIN 
   dbms_output.put_line(TRUNC(Test_Number number1, 
                              Test_Number number2)); 
   
END;  

Output:

15.31

In the above example, the truncated value of 15.3123 is 15.31 because here 2 is at the place of decimal_place parameter and it shows that the output value must contain 2 decimal number after the decimal point.

Advantage:
This function is used to return a number truncated to a particular number of decimal places.

My Personal Notes arrow_drop_up
Recommended Articles
Page :