How to Find and Replace Text in MySQL Database using SQL Làm thế nào để Tìm và Thay thế văn bản trong cơ sở dữ liệu MySQL sử dụng SQL
MySQL database has a handy and simple string function REPLACE() that allows table data with the matching string (from_string) to be replaced by new string (to_string). Cơ sở dữ liệu MySQL có một đơn giản, tiện dụng và chức năng REPLACE chuỗi () cho phép dữ liệu bảng với chuỗi kết hợp (from_string) để được thay thế bằng chuỗi mới (to_string). This is useful if there is need to search and replace a text string which affects many records or rows, such as change of company name, postcode, URL or spelling mistake. Điều này rất hữu ích nếu có cần phải tìm kiếm và thay thế một chuỗi văn bản có ảnh hưởng đến nhiều hồ sơ hay các hàng, chẳng hạn như thay đổi tên công ty, postcode, URL hoặc sai chính tả.
The syntax of REPLACE is REPLACE(text_string, from_string, to_string) Cú pháp của REPLACE là REPLACE (text_string, from_string, to_string)
MySQL reference MySQL tham khảo describes REPLACE as function that returns the string text_string with all occurrences of the string from_string replaced by the string to_string, where matching is case-sensitive when searching for from_string. REPLACE mô tả như là chức năng mà sẽ trả về chuỗi text_string với tất cả các lần xuất hiện của chuỗi from_string thay thế bằng chuỗi to_string, nơi kết hợp là trường hợp-nhạy cảm khi tìm kiếm from_string. text_string can be retrieved from the a field in the database table too. text_string có thể được lấy từ một trường trong bảng cơ sở dữ liệu quá. Most SQL command can be REPLACE() function, especially SELECT and UPDATE manipulation statement. Hầu hết các lệnh SQL có thể được REPLACE () chức năng, đặc biệt là SELECT và UPDATE thao tác tuyên bố.
For example: Ví dụ:
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, 'find this string', 'replace found string with this string'); Cập nhật TABLE_NAME đặt FIELD_NAME = thay thế (FIELD_NAME, 'tìm thấy chuỗi này', 'thay thế hàng chuỗi với chuỗi này');
update client_table set company_name = replace(company_name, 'Old Company', 'New Company') Cập nhật company_name đặt client_table = thay thế (company_name, 'Old ty', 'Công ty mới')
The above statement will replace all instances of 'Old Company' to 'New Company' in the field of company_name of client_table table. Những tuyên bố trên đây sẽ thay thế tất cả các trường hợp 'Old ty' thành 'Công ty mới' trong lĩnh vực company_name của bảng client_table.
Another example: Một ví dụ khác:
SELECT REPLACE('www.mysql.com', 'w', 'Ww'); SELECT REPLACE ( 'www.mysql.com', 'w', 'Ww');
Above statement will return 'WwWwWw.mysql.com' as result. Ở trên tuyên bố sẽ trở lại 'WwWwWw.mysql.com' như là kết quả.
IMPORTANT : The page is machine translated and provided "as is" without warranty. Quan trọng: Sửa là máy dịch và cung cấp "như là" không có bảo hành. Machine translation may be difficult to understand. Máy dịch thuật có thể khó hiểu. Please refer to Vui lòng tham khảo original English article bản gốc tiếng Anh bài viết whenever possible. bất cứ khi nào có thể.
Related Articles Bài viết liên quan
- Remove or Trim First or Last Few Characters in MySQL Database with SQL Hủy bỏ hoặc Trim Nhân vật đầu tiên hoặc ít Lần trong cơ sở dữ liệu MySQL với SQL
- Check and Optimize MySQL Database Automatically with Crontab/Cron Kiểm tra và Tối ưu hóa cơ sở dữ liệu MySQL Tự động với Crontab / định kỳ
- MySQL Error 1170 (42000): BLOB/TEXT Column Used in Key Specification Without a Key Length MySQL Error 1170 (42000): BLOB / TEXT Cột Được sử dụng trong khóa kỹ thuật Nếu không có một Chiều dài khóa
- MySQL Database Performance Tuning Best Practices Video Tutorial Cơ sở dữ liệu MySQL Performance Tuning Best Practices Video Tutorial
- Enable Logging of Slow Queries (Slow Query Log) in MySQL Database Enable Logging of Slow Queries (Slow Query Log) trong cơ sở dữ liệu MySQL
- Change and Reset MySQL root Password Thay đổi và Thiết lập lại mật khẩu root MySQL
- Replace Notepad with Another Text Editor (eg. Notepad2 and Notepad++) in Vista Thay thế Notepad bằng Một biên tập văn bản (ví dụ: Notepad2 và Notepad + +) trong Vista
- Download File Content Replacer to Search and Replace Text in Multiple Files Nội dung file Replacer để tìm kiếm và thay thế trong nhiều tập tin văn bản
- Using PHP-MySQL Persistent Connections to Run WordPress Blog Sử dụng PHP-MySQL Persistent Connections để Khởi WordPress Blog
- How to Backup and Restore (Export and Import) MySQL Databases Tutorial Làm thế nào để sao lưu và khôi phục (xuất khẩu và nhập khẩu) Cơ sở dữ liệu MySQL Tutorial










































September 30th, 2009 15:26 30 Tháng chín 2009 15:26
Wanted to use REPLACE command to use for a column of a table…and this helped me…thanks Muốn sử dụng lệnh REPLACE để sử dụng cho một cột của một bảng ... và điều này đã giúp tôi ... nhờ