Home > Database > Oracle > body text

How to use trim in oracle

下次还敢
Release: 2024-04-30 07:54:15
Original
649 people have browsed it

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>
Copy after login

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>
Copy after login

This will return a trimmed string:

<code>Hello, world!</code>
Copy after login

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>
Copy after login

This will return the trimmed string:

<code>Hello</code>
Copy after login

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>
Copy after login

This will return the trimmed string:

<code>Hello!</code>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template