SQL Replacement Statement Bulk Modify, add, delete field contents

Source: Internet
Author: User

SQL substitution statement, which allows the whole batch to replace the contents of a field, or to add or remove characters from the original field in bulk.

Command Total Solution: The name of the Update table set this table to replace the field name =replace (this table to replace the field name, ' original content ', ' new content ')

such as UPDATE Whir_productrelese SET relesename=replace (relesename, ' AA ', ' BB ')

To illustrate:

1) Change all the characters in the field contents of the Backupfile table URL to BB.

Update backupfile set url=replace (URL, ' AAA ', ' BBB ')

2) Add the contents of the field according to the conditions, such as adding TMP to the contents of the Logical_name field of the File_number=1 record, followed by end.

Update backupfile set Logical_name=replace (logical_name,logical_name, ' tmp ' +logical_name+ ' End ') where file_number=1

3) Remove the first 2 characters of the specified record according to the conditions.

Update backupfile Set Logical_name=replace (logical_name,logical_name,substring (Logical_name,3,len (logical_name)-2 )) where file_number=1

4) Remove the following 4 characters from the specified record according to the conditions.

Update backupfile Set Logical_name=replace (logical_name,logical_name,substring (Logical_name,1,len (logical_name)-4 )) where file_number=2

If it is unclear, you can use the SELECT statement to verify that you have achieved your desired effect before replacing it:

SELECT Replace (replace field, ' original content ', ' new content ') from table name;

Update table name set replace field = (replace (replacement field, ' original content ', ' new content ')

SQL Replacement Statement Bulk Modify, add, delete field contents

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.