What is the difference between TRIM and Truncate functions in oracle

Showing Answers 1 - 23 of 23 Answers

Naseem

  • Aug 23rd, 2006
 

Trim- enables to trim the characters from the string i.e from either sides

Eg: trim ('0' from '001')

Trunc- truncates the value to specified decimal

Eg:trunc(198.06,2)

or truncates the date to nearest date

Eg:trunc(sysdate,'year')

josna

  • Aug 29th, 2006
 

thanks

  Was this answer useful?  Yes

srinivas

  • Nov 28th, 2006
 

TRIM means it will avoid the empty character cells . TRUNCATE means it will avoide the fraction part of a value

  Was this answer useful?  Yes

lieni

  • Jan 16th, 2007
 

TRUNC and TRUNCATE are 2 different functions, above you mentioned only the TRUNC function
truncate table <tbl>
will delete all records of the table

  Was this answer useful?  Yes

SRINAVAS AVULA

  • Jan 5th, 2013
 

->Trim is a oracle system defined function used for deleting the free spaces in a given string or number.

->Truncate is a ddl command in oracle used for deleting all the data of a table...

  Was this answer useful?  Yes

rayavarapu

  • Feb 4th, 2013
 

Trim is Oracle pre-defined function it is used for deleting free spaces of given string.

Truncate is Oracle DDL command it is used for deleting a table.

  Was this answer useful?  Yes

Varun Tiwari

  • Jul 4th, 2013
 

Trim: It is oracle defined function to remove the blank spaces from left and right of a string or we can say it is combination of ltrim and rtrim.

Truncate: This is used to delete all the records of a table (Truncate table table_name) and the advantage of using truncate in comparison to delete statement is that it resets the high water mark.

-Varun

  Was this answer useful?  Yes

shiiva

  • Aug 6th, 2013
 

We cannot compare Truncate & Trim. Truncate is a DDL command which deletes the content of a table completely, without effecting the table structure.

Trim is a function which alters the output of one of the column output of a select query.

  Was this answer useful?  Yes

Deepika S Verma

  • Mar 14th, 2014
 

TRUNC applies to numeric and Dates values
Syntax-
-------
TRUNC( number, [ decimal_places ] )
TRUNC ( date, [ format ] )

Example -
---------
TRUNC(125.815) would return 125
TRUNC(125.815, 0) would return 125
TRUNC(125.815, 1) would return 125.8
TRUNC(125.815, 2) would return 125.81
TRUNC(125.815, 3) would return 125.815
TRUNC(-125.815, 2) would return -125.81
TRUNC(125.815, -1) would return 120
TRUNC(125.815, -2) would return 100
TRUNC(125.815, -3) would return 0

TRUNC(TO_DATE(22-AUG-03), YEAR) would return 01-JAN-03
TRUNC(TO_DATE(22-AUG-03), Q) would return 01-JUL-03
TRUNC(TO_DATE(22-AUG-03), MONTH) would return 01-AUG-03
TRUNC(TO_DATE(22-AUG-03), DDD) would return 22-AUG-03
TRUNC(TO_DATE(22-AUG-03), DAY) would return 17-AUG-03


TRIM function removes all specified characters either from the beginning or the ending of a string.

Syntax-
-------
TRIM( [ LEADING | TRAILING | BOTH [ trim_character ] string1 )

Example -
---------
TRIM( tech ) would return tech
TRIM( FROM tech ) would return tech
TRIM(LEADING 0 FROM 000123) would return 123
TRIM(TRAILING 1 FROM Tech1) would return Tech
TRIM(BOTH 1 FROM 123Tech111) would return 23Tech

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions