MySQL replaces characters with replace in SQL statements

Source: Internet
Author: User

Originally do not want to tell you, because the collection of other people's website is not a glorious thing, but feel that this technique is strong enough, if this short line of code, I am not exhausted. Is this, collected some other people's article, may be the collection procedure question, each article title has some more characters

The code is as follows Copy Code

Update dede_addonsoft SET dxylink=replace (Dxylink, '. zip ', '. rar ') where aid > 45553;

Update ' table_name ' SET field = replace (field, '. rar ', '. 7z ');

TABLE_NAME: The name of the table to query,
Field name in the list,

Replace (field, '. rar ', '. 7z '); : Regular match, replacing. rar in field fields with. 7z

Do not see anything, but I looked at the database, WOW!! Really cool, All disappeared, think this statement is really strong, also blame themselves don't understand SQL unexpectedly have so usage ah, later to more research SQL, with less effort AH. So I am afraid to share this experience with you. Another report, I now do not engage in collection, like a person as honest to do the station, look forward to everyone's station also has a good harvest. By the way, the meaning of this line of code:

Update ' table name (for example, my article) ' Set to modify the field name = replace (field name to be modified, ' replaced character ', ' replaced character ')

Add:

MySQL Replace usage
1.replace into

Replace into table (Id,name) VALUES (' 1 ', ' AA '), (' 2 ', ' BB ')

The purpose of this statement is to insert two records into table tables. If the primary key ID is 1 or 2 does not exist
is equivalent

Insert into table (Id,name) VALUES (' 1 ', ' AA '), (' 2 ', ' BB ')

Data is not inserted if the same value exists

2.replace (Object,search,replace)

Replaces all occurrences of search in object with replace
Select replace (' www.163.com ', ' w ', ' Ww ')--->wwwwww.163.com
To replace a AA in the Name field in table tables with BB
Update table Set Name=replace (name, ' AA ', ' BB ')

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.