BTRIM

BTRIM is an SQL function that facilitates the removal of leading or trailing characters, referred to as trim characters, from a string. It's typically used when there's a need to perform operations on strings without particular characters from the beginning or the end of the string.

BTRIM(string text [, trim_string text]) RETURNS text

  • string text: This is the primary input string from which the leading and trailing spaces or characters will be removed. The function processes this parameter to identify and eliminate excess spaces or defined characters at both ends of the input string.
  • trim_string text: This is an optional parameter. If provided, the function removes any characters that match with any characters in the trim_string from the beginning or end of the string text. When not provided, the function defaults to removing leading and trailing spaces.

Example

SELECT BTRIM(' PostgreSQL ');

Output

"PostgreSQL"

Explanation

The BTRIM function in SQL is used to remove the leading and trailing spaces from the string. In the provided example, the string ’ PostgreSQL ’ has spaces at the beginning and the end. After applying BTRIM, these spaces are removed and we are left with the trimmed output “PostgreSQL”.

BTRIM(text VARCHAR2, trim_character VARCHAR2 DEFAULT NULL) RETURN VARCHAR2;

  • text varchar2: This is the input string that will be processed by the BTRIM function. It represents the sequence of characters from which the trim_character will be removed if found at the beginning of the string.
  • trim_character varchar2 default null: This is an optional parameter which, when specified, becomes the set of characters to be removed from the beginning of the input text. If this parameter is not specified, the function will by default remove spaces from the beginning of the text.

Example

SELECT BTRIM(' Oracle SQL ') AS Trimmed_String FROM dual;

Output

Trimmed_String
--------------
Oracle SQL

Explanation

The BTRIM function in Oracle SQL removes leading and trailing spaces from a string. In the provided example, BTRIM is used to trim the spaces from the string ’ Oracle SQL ’, resulting in ‘Oracle SQL’.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.