The TRUNC function is an inbuilt function in PLSQL which is used to return a number truncated to a particular number of decimal places.
TRUNC( number, decimal_places )
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.
This function returns a numeric value truncated to a particular number of decimal places.
Supported Versions of Oracle/PLSQL:
- Oracle 12c
- Oracle 11g
- Oracle 10g
- Oracle 9i
- Oracle 8i
Let’s see some examples which illustrate the TRUNC function:
DECLARE Test_Number number := 5.5; BEGIN dbms_output.put_line(TRUNC(Test_Number number)); END;
In the above example, the truncated value of 5.5 is 5
DECLARE Test_Number number1 := 5; Test_Number number2 := 0; BEGIN dbms_output.put_line(TRUNC(Test_Number number1, Test_Number number2)); END;
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.
DECLARE Test_Number number1 := 15.3123; Test_Number number2 := 2; BEGIN dbms_output.put_line(TRUNC(Test_Number number1, Test_Number number2)); END;
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.
This function is used to return a number truncated to a particular number of decimal places.
- PLSQL | LEAST Function
- PLSQL | LOG Function
- PLSQL | EXP Function
- PLSQL | LN Function
- PLSQL | MOD Function
- PLSQL | CHR Function
- PLSQL | SIN Function
- PLSQL | ABS Function
- PLSQL | COS Function
- PLSQL | TAN Function
- PLSQL | NCHR Function
- PLSQL | FLOOR Function
- PLSQL | CEIL Function
- PLSQL | REPLACE Function
- PLSQL | ASCII Function
- PLSQL | DBTIMEZONE Function
- PLSQL | EXTRACT Function
- PLSQL | COSH Function
- PLSQL | TRIM Function
- PLSQL | LENGTH2 Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.