Replaces the first occurrence of a character in a string with a specific character

Source: Internet
Author: User

The Replace function can directly change a particular value in a string or field to a value that needs to be replaced


If you replace only the first or second occurrence of a character, we can use InStr to get the implementation:

Select Replace (substr (Col,1,instr (col, ' a ', 1) +length (' a ')-1), ' A ', ' 0 ')

|| substr (Col,instr (col, ' a ', 1) +length (' a '))

From (

Select ' C,a,b,c,a,d ' as Col from dual);



PostgreSQL

Select Replace (substring (col,1,position (' ab ' in col) +length (' AB ')-1), ' ab ', ' # # # ') | | SUBSTRING (col,position (' ab ' in col) +length (' AB '))

From (

Select ' C,ab,b,c,a,d ':: text as col) T;


This article is from the "8016776" blog, please be sure to keep this source http://8026776.blog.51cto.com/8016776/1688085

Replaces the first occurrence of a character in a string with a specific character

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.