Home >Database >Oracle >What is the usage of oracle trim?

What is the usage of oracle trim?

青灯夜游
青灯夜游Original
2022-04-18 18:44:3118280browse

In Oracle, the trim() function is used to remove specified characters at the beginning and end of a string. This function can support two parameters. The first parameter sets the string to be processed, and the second parameter sets The characters that need to be removed. This parameter can be omitted. If not set, the space characters on both sides will be removed by default; the syntax is "TRIM (string [, character])".

What is the usage of oracle trim?

The operating environment of this tutorial: Windows 7 system, Oracle 11g version, Dell G3 computer.

In Oracle, the TRIM() function allows developers to trim characters from both sides of a string, removing specified characters.

The TRIM() function supports two parameters. By default, it removes whitespace characters, but you can choose to specify different characters to trim.

TRIM(X[,Y])

Remove the Y strings on both sides of the string X. When Y is not filled in, the default is to remove the spaces around the string String

  • Parameter Y: Set the characters to be removed, which can be omitted. The space characters on both sides are removed by default.

  • Example:

  • SELECT TRIM(' dd df ') FROM dual;
Output:



Extended knowledge: What is the usage of oracle trim?


rtrim(string); --Remove spaces on the right side of the string

  • ltrim(string); -- Remove the spaces on the left side of the string

  • ##ltrim(string1,string2);

    --Traverse from the left side of string1. Once a certain character appears in string2 (here string2 is a character set), remove it. If it does not exist, the result is returned directly.
For example:

select ltrim('abcdefg', 'fegab') from dual;
Return: cdefg

rtrim(string1,string2);

--Traverse from the right side of string1, once it exists If a character appears in string2 (where string2 is a character set), it is removed. If it does not exist, the result is returned directly.

Give a chestnut:

select rtrim('abcdefg', 'fegab') from dual;
Return: abcd

Recommended tutorial: "

Oracle Tutorial

"

The above is the detailed content of What is the usage of oracle trim?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn