Home  >  Article  >  Database  >  How to use trim in oracle

How to use trim in oracle

下次还敢
下次还敢Original
2024-04-30 07:54:15615browse

The TRIM function in Oracle is used to remove spaces or specific characters at both ends of a string. The syntax is: TRIM([trim_character] FROM string). It can remove all spaces in a string (trim_character parameter is omitted), it can remove specified characters (specify trim_character parameter), or even remove multiple specified characters (specify multiple trim_character parameters). It should be noted that the TRIM function does not remove spaces in the middle of the string.

How to use trim in oracle

Usage of TRIM function in Oracle

TRIM function is used in Oracle to remove spaces or spaces at both ends of a string. Function for specifying characters. It uses the following syntax:

<code>TRIM([trim_character] FROM string)</code>

where:

  • trim_character (optional): The character to be removed. If omitted, spaces are removed.
  • string: The string to be trimmed.

How to use the TRIM function?

To use the TRIM function, simply pass the string you want to trim as a parameter. For example:

<code>SELECT TRIM('  Hello, world!  ') FROM dual;</code>

This will return a trimmed string:

<code>Hello, world!</code>

Remove specific characters

The TRIM function can also remove specific characters from a string. To do this, specify the character to be removed in the trim_character parameter. For example:

<code>SELECT TRIM('---Hello---' FROM '-') FROM dual;</code>

This will return the trimmed string:

<code>Hello</code>

Using multiple trim_character

TRIM function can receive multiple trim_character as parameters , to remove multiple characters from a string. For example:

<code>SELECT TRIM('##Hello!##' FROM '#!') FROM dual;</code>

This will return the trimmed string:

<code>Hello!</code>

Note:

  • TRIM function does not remove the middle of a string of spaces.
  • If you want to remove spaces in the middle of a string, you can use the REPLACE function.

The above is the detailed content of How to use trim in oracle. 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