Home  >  Article  >  Database  >  How to remove leading and trailing spaces in oracle

How to remove leading and trailing spaces in oracle

WBOY
WBOYOriginal
2022-05-18 18:09:548296browse

In Oracle, you can use the trim() function to remove leading and trailing spaces. When the parameter of this function is set to both, the specified first and last characters will be removed. The syntax is "select trim(both ' ' from field) as strTemp from tableName".

How to remove leading and trailing spaces in oracle

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

How to remove leading and trailing spaces in oracle

In Oracle, the usage of trim() function is: leading starting character, trailing ending character, both starting and ending characters, as follows:

trim(leading || trailing || both '将要被替换掉的字符" from “将要被替换的字符串")

1. The trim function removes the specified starting characters

select trim(leading 'x' from 'xday') as strTemp from tableName ;

2. The trim function removes the specified ending characters

select trim(trailing 'x' from 'dayx') as strTemp from tableName ;

3. The trim function removes the specified first and trailing characters

select trim(both 'x' from 'xdayx') as strTemp from tableName ;

4. By default, the trim function will remove the leading and trailing characters.

select trim('x' from 'xdayx') as strTemp from tableName ;

5. If the characters to be removed are not specified, the leading and trailing spaces will be removed by default.

select trim(' day ') as strTemp from tableName ;

Extended knowledge:

The syntax is described as follows:

TRIM([ { { LEADING | TRAILING | BOTH }
         [ trim_character ]
       | trim_character
       }
       FROM 
     ]
     trim_source
    )

Parameter explanation:

leading Starting character

trailing Ending character

both Beginning and ending character

trim_character Character removed

trim_source Trimming source

Recommended tutorial: "Oracle Video Tutorial

The above is the detailed content of How to remove leading and trailing spaces 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