Trimming Characters with TRIM()

Use the TRIM() function to remove unwanted characters from the ends of a string. The TRIM() function’s important characteristics are:

  • You can trim leading characters, trailing characters, or both. (You can’t use TRIM() to remove characters from within a string.)

  • By default, TRIM() trims spaces, but you can strip off any unwanted characters, such as leading and trailing zeros or asterisks.

  • TRIM() typically is used to format results and make comparisons in a WHERE clause.

  • TRIM() is useful for trimming trailing spaces from CHAR values. Recall from “Character String Types” in Chapter 3 that DBMSes automatically add spaces to the end of CHAR values to create strings of exactly a specified length.

  • Trimming has no effect ...

Get SQL: Visual QuickStart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.