Trim,ltrim,rtrim function usage in Oracle

Source: Internet
Author: User
Tags rtrim

There are two kinds of functions in this function:
the first, that is, everyone is more familiar with the removal of space.
Example:
--trim to remove spaces before and after a specified character
sql> SELECT TRIM (' DD DF ') from dual;
TRIM (' Dddf ')
------------
DD DF

--ltrim Remove the front space of the specified character
sql> SELECT LTRIM (' DD DF ') from dual;
LTRIM (' Dddf ')
-------------
DD DF

--rtrim remove space after the specified character
sql> SELECT RTRIM (' DD DF ') from dual;
RTRIM (' Dddf ')
-------------
DD DF

The second, removes the specified character. Trim can only remove single characters, while LTrim and RTrim can remove multiple characters.
Trim to remove a character's wording:
--Represents the string string2 to remove the character string1 of the front | back | front side (leading|trailing|both), the default removal method is both
SELECT TRIM (Leading|trailing|both string1 from string2) from dual;
Example:
Sql> SELECT Trim (leading ' d ' from ' Dfssa ') from dual;
TRIM (Leading ' D ' from ' Dfssa ')
---------------------------
Fssa

Sql> SELECT Trim (both ' 1 ' from ' 123sfd111 ') from dual;
TRIM (BOTH ' 1 ' from ' 123sfd111 ')
----------------------------
23sfd

Sql> SELECT Trim (trailing ' 2 ' from ' 213dsq12 ') from dual;
TRIM (TRAILING ' 2 ' from ' 213dsq12 '
------------------------------
213dsq1

Note: The trim removal character can only be a single character, such as the following, the character to be removed characters as a character set error
Sql> SELECT trim (trailing ' from ' 123dsq12 ') from dual;
SELECT trim (trailing ' from ' 123dsq12 ') from dual
ORA-30001: The Intercept set can have only one character

LTrim and RTrim to remove characters:
--Indicates that the string string1 removes the previous match to the string2 character set, and if no match ends the return
SELECT LTrim (string1,string2) from dual;
--rtrim is similar to LTrim, except that it removes the matching character from the right side.
SELECT RTrim (string1,string2) from dual;
Example:
--as follows, because the first letter from the right side is B does not match the ' main ' character, so the returned result is still ' aaaaminb '
sql> SELECT RTrim (' aaaaminb ', ' main ') from dual;
RTRIM (' aaaaminb ', ' MAIN ')
------------------------
Aaaaminb

--The returned result is empty as follows
sql> SELECT RTrim (' aaaaminb ', ' mainb ') from dual;
RTRIM (' aaaaminb ', ' mainb ')
-------------------------

sql> SELECT ltrim (' ccbcminb ', ' CB ') from dual;
LTRIM (' ccbcminb ', ' CB ')
----------------------
Minb

Trim,ltrim,rtrim function usage in Oracle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.