Replacement functions in Oracle Replace and translate functions

Source: Internet
Author: User
Tags translate function

1. TRANSLATE syntax: TRANSLATE (Char, from, tousage: Returns a string that replaces each character that appears in the From, with the corresponding character in to.            If the from is longer than the to string, then the characters that are more than to in the from will be deleted. One of the three parameters is empty, and the return value will also be a null value. Example: SQL> SelectTranslate'ABCDEFGA','ABC','wo') return value fromdual; return value-------WODEFGW Analysis: This statement will be'ABCDEFGA'In the'ABC'Converted to'wo', since'ABC'In'a'Corresponding'wo'In the'W', it will'ABCDEFGA'In the'a'Convert all into'W'; and'ABC'In'b'Corresponding'wo'In the'o', it will'ABCDEFGA'In the'b'Convert all into'o'; 'ABC'In the'C'In'wo'does not correspond to the characters in the'ABCDEFGA'In the'C'Delete all;            Simply put, the character in the from is converted to the character corresponding to the position in to, and if the corresponding character is not found in to, the character in the return value is deleted.            In the actual business, can be used to delete some of the exception data, such as Table A field t_no represents a telephone number, and the phone number itself should be a string consisting of numbers, in order to delete those containing non-numeric exception data, I used the Translate function: SQL> Delete  fromA,whereLength (Translate (Trim (a.t_no),'0123456789' ||A.t_no,'0123456789'))<>Length (Trim (a.t_no));2.ReplaceSyntax:REPLACE(Char, search_string,replacement_string) Usage: Converts all string search_string in char to string replacement_string. Example: SQL> Select REPLACE('fgsgswsgs','FK','J') return value fromdual; return value---------fgsgswsgs SQL> Select REPLACE('fgsgswsgs','SG','EEERRRTTT') return value fromdual; return value-----------------------Fgeeerrrtttsweeerrrttts Analysis: In the first example, as a result of'fgsgswsgs'does not match the'FK'matches the string, so the return value is still'fgsgswsgs'; The second example will'fgsgswsgs'The string in'SG'Convert All to'EEERRRTTT'. Summary: To sum up, replace and translate are alternative functions, except that replace is for a string, and translate is for a single character. 

Transferred from: https://www.cnblogs.com/xiaoqisfzh/p/5620890.html

Replacement functions in Oracle Replace and translate functions

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.