Modify, add, or delete fields using SQL Replace statements in batches.

Source: Internet
Author: User

Modify, add, or delete fields using SQL Replace statements in batches.

SQL replacement statement. You can use this command to replace the content of a field in the whole batch, or add or remove characters to or from the original field content in batches.

Command General Solution: update table name set the field name to be replaced in this table = REPLACE (the Field name to be replaced in this table, 'original content', 'new content ')

For example, UPDATE Whir_ProductRelese SET ReleseName = REPLACE (ReleseName, 'HTTP: // www.maidq.com ', 'HTTP: // maidq.com ')

Example:

1) In the backupfile table url field content for the http://www.maidq.com of all characters to http://maidq.com.

 update backupfile set url=REPLACE(url,'http://www.maidq.com','http://maidq.com')

2) Add the field content according to the conditions. For example, add tmp to the content of the logical_name field of the record with file_number = 1, and end to the record.

 update backupfile set logical_name=REPLACE(logical_name,logical_name,'tmp'+logical_name+' end ') where file_number=1

3) Remove the first two characters of the specified Record Based on the condition.

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 four characters after the specified Record Based on the condition.

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 whether the desired effect is achieved and then replace it:

Select replace (REPLACE field, 'original content', 'new content') from table name; update table name set REPLACE field = (REPLACE field, 'original content ', 'New content '))

The above section describes how to modify, add, and delete fields using SQL Replace statements in batches. I hope it will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.