Oracle replace () function usage

Source: Internet
Author: User

In the oracle database, we will use the replace function to replace strings. The following describes how to use replace () in oracle. For more information, see.

Usage

REPLACE (char, search_string [, replacement_string])

Char: string to be replaced

Search_string: Search for the string to be replaced

Replacement_string: replace string

If replacement_string is null by default, all search_string characters in char will be removed.

If search_string is null, the result is char.

The Code is as follows: Copy code

Select replace ('Jack and JUE ', 'J', 'bl') "Changes" from dual;

Example 1

In the format of '2017-10-11 'in the database, the imported data is '2017/11'

The Code is as follows: Copy code

Update Table 1 t set t. column 1 = replace (select column 1 from table 1 a where. primary Key column = t. primary Key column), '/', '-') solves our problem.

Replace string-level replacement

For example:

The Code is as follows: Copy code
Select replace ('accd', 'cd', 'ef ') from dual; --> aefd

Replacement of the translate character level

For example:

The Code is as follows: Copy code
Select translate ('acdd', 'cd', 'ef ') from dual; --> aeff

 

Detailed explanation

Replace:

Syntax: REPLACE (char, search_string [, replacement_string])

Explanation: In replace, each search_string is replaced by replacement_string.

The Code is as follows: Copy code

Select replace ('acdd', 'cd', 'ef ') from dual; --> aefd

If replacement_string is null or null, all search_strings are removed.

The Code is as follows: Copy code

Select replace ('acdd', 'cd', '') from dual; --> ad

If search_string is null, the original char is returned.

The Code is as follows: Copy code

Select replace ('acdd', 'ef ') from dual; --> acdd

Elect replace ('acdd', '','') from dual; --> acdd

(This is also the case where both are empty)

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.