• Skip to primary navigation
  • Skip to main content

Tech Honey

The #1 Website for Oracle PL/SQL, OA Framework and HTML

  • Home
  • HTML
    • Tags in HTML
    • HTML Attributes
  • OA Framework
    • Item in OAF
    • Regions in OAF
    • General OAF Topics
  • Oracle
    • statement
    • function
    • clause
    • plsql
    • sql
You are here: Home / Oracle / function / Oracle PL/SQL TRIM Function

Oracle PL/SQL TRIM Function

November 26, 2012 by techhoneyadmin

Oracle PLSQL TRIM FunctionSQL TRIM Function is used to remove the specified characters from left and right sides of a string. Oracle TRIM Function returns the remaining string after removing the specified characters from left and right side of a string. PLSQL TRIM Function syntax with SQL TRIM String and SQL TRIM WHITESPACE examples are mentioned below.


Oracle TRIM Function Syntax

SELECT TRIM([trailing | leading | both [trim characters]] string_1)
FROM table_name;

In the above Oracle TRIM Function Syntax:-

  • string_1 is the string to be trimmed
  • ‘Leading’ will remove the trim_characters from start_position in string_1.
  • ‘Trailing’ will remove the trim_characters from the end of the string_1.
  • ‘Both’ will remove the trim_characters from beginning and end of string_1
  • If we omit ‘leading’, ‘trailing’ or ‘both’ from the TRIM function then the TRIM function trims the string_1 from beginning and end.
  • If no trim_charachter is mentioned then TRIM function removes the white spaces from string_1

Oracle TRIM Function – Use in SQL TRIM String Example

Oracle TRIM Function can be used with the SQL SELECT Statement to TRIM a string.

For example, the below SQL TRIM String query returns the string after stripping the white spaces from left and right sides.

SELECT TRIM(' Tech Honey ')"SQL TRIM String"
FROM dual;

The above SQL TRIM String example returns ‘Tech Honey’

Note: We have aliased TRIM(‘ Tech Honey ‘) as SQL TRIM String.


Oracle TRIM Function – SQL TRIM WHITESPACE Example

Oracle TRIM Function can be used in SQL TRIM WHITESPACE query.

For example, the SQL TRIM WHITESPACE query below returns the string after removing the whitespaces from left and right side.

SELECT TRIM(' ' from ' Tech Honey ') "SQL TRIM WHITESPACE"
FROM dual;

The above SQL TRIM WHITESPACE query returns ‘Tech Honey’

Note: We have aliased TRIM(‘ ‘ from ‘ Tech Honey ‘) as SQL TRIM WHITESPACE.


Oracle TRIM Function – Removing LEADING Characters Example

Oracle TRIM Function can be used to remove any leading character from a string.

For example, the below PLSQL TRIM Function query returns the string after removing all the leading 1s from the string.

SELECT TRIM(LEADING 1 FROM '1111Tech Honey11111') "PLSQL TRIM Function"
FROM dual;

The above PLSQL TRIM Function query returns ‘Tech Honey11111’

Note we have aliased TRIM(LEADING 1 FROM ‘1111Tech Honey11111’) as PLSQL TRIM Function.


Oracle TRIM Function – Removing TRAILING Characters Example

PLSQL TRIM Function can be used to remove any trailing character from a string.

For example, the below TRIM Function query returns the string after removing all the trailing 1s from the string.

SELECT TRIM(TRAILING 1 FROM '1111Tech Honey11111') "PLSQL TRIM Function"
FROM dual;

The above PLSQL TRIM Function query returns ‘1111Tech Honey’.

Note: We have aliased TRIM(TRAILING 1 FROM ‘1111Tech Honey11111’) as PLSQL TRIM Function.


Oracle TRIM Function – Removing LEADING and TRAILING Characters Example

Oracle TRIM Function can be used to remove both the LEADING and TRAILING characters from a string.

For example, the TRIM Function query returns the string after removing leading and trailing 1s from the string.

SELECT TRIM(BOTH 1 FROM '1111Tech Honey11111') "Oracle TRIM Function"
FROM dual;

The above TRIM Function query returns ‘Tech Honey’.

Note: We have aliased TRIM(BOTH 1 FROM ‘1111Tech Honey11111’) as Oracle TRIM Function.


Filed Under: function Tagged With: how to use TRIM Function in oracle database query, how to use TRIM Function in oracle plsql, how to use TRIM Function in oracle sql, syntax and example of TRIM Function in oracle database query, syntax and example of TRIM Function in oracle plsql, syntax and example of TRIM Function in oracle sql, TRIM Function in oracle plsql, TRIM Function in oracle sql, TRIMPLSQL, using TRIM Function in oracle database query, using TRIM Function in oracle plsql, using TRIM Function in oracle sql

Copyright © 2025 · Parallax Pro on Genesis Framework · WordPress · Log in