Hongmu Notes
Home Language Notes Replace the content of a specified field in a MySQL data table with the text preceding the content.
Language Notes mySql

Replace the content of a specified field in a MySQL data table with the text preceding the content.

Replace the content of a specified field in a MySQL data table with the text preceding the content.

It might sound a bit convoluted, but the meaning is correct!

For example, the field content could be: [Hello, I'm your friend]

Now, I would like to replace the content preceding "[I am]" with an empty string.

That's the effect.

You can use MySQL string functions. SUBSTRING_INDEX() combine REPLACE() Implement using a function. Below is an example code:

UPDATE 表名 SET 字段名 = REPLACE(字段名, SUBSTRING_INDEX(字段名, '我是', 1), '')

for instance:

UPDATE phome_ecms_news_data_1 SET newstext = REPLACE(newstext, SUBSTRING_INDEX(newstext, '我是一个很帅气的分割线', 1), '')

 

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

sqlite uses PDO to execute SQL statements exec(), query()

sqlite uses PDO to execute SQL statements exec(), query() Language Notes mySql

In PHP scripts, executing SQL queries using PDO to interact with a database can be done through three different approaches; the choice of which method to use depends on the specific operation you intend to perform. 1. Using the PDO::exec() method: When executing queries such as INSERT, UPDATE, or DELETE that do not return a result set, use the exec() method on a PDO object to execute the query. Upon successful execution, this method returns the number of affected rows...
👁 323
Mysql efficiency improvement: limit this piece of shit

Mysql efficiency improvement: limit this piece of shit Language Notes mySql

In mysql, the efficiency of limit is not high, especially my millions of data, limit 100000, 50, so writing, the query is even slower, at first it was quite fast, and the server cup behind it was directly filled for me! I thought the server was hacked, so I looked for the problem. I looked for it for a few days, but it turned out to be this dog, which made me angry! So I inquired about the principle of limit, emmm, change! Must be changed ...
👁 155
SQL statement to truncate the database

SQL statement to truncate the database Language Notes mySql

The TRUNCATE command can be used to clear a table; however, if you need to clear an entire database, you must clear each table individually. Below is an example SQL statement for clearing an entire database: SET foreign_key_checks = 0; SELECT CONCAT('TRUNCATE TABLE `',table_name,'`;') FR...
👁 297

Recommended reading

Marketing-oriented Fire Extinguisher and Firefighting Equipment Website Template 0174

Marketing-oriented Fire Extinguisher and Firefighting Equipment Website Template 0174 Practical Collection Yiyou template

An eYouCMS website template designed for marketing-oriented fire extinguisher, firefighting equipment, and apparatus manufacturers. Its eye-catching and professional design enables effective presentation of firefighting products, safety equipment, technical specifications, and project case studies. This template helps firefighting equipment companies showcase their products online, attracting both corporate and government procurement opportunities. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Common Installation Issues with eYouCMS...
👁 28
(PC+WAP) Carton Packaging Website – pbootCMS Template; Download Source Code for Carton Packaging Materials Websites – 0082

(PC+WAP) Carton Packaging Website – pbootCMS Template; Download Source Code for Carton Packaging Materials Websites – 0082 Practical Collection pbootcms Template

A PbootCMS website template designed specifically for the carton, box, and packaging materials industry, compatible with both PC and WAP devices. Its clean and professional design effectively showcases the variety of carton packaging products and the company's customization capabilities. This template is an ideal tool for carton manufacturers or packaging companies to create a branded official website, demonstrate their production capabilities, and secure orders. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extract...
👁 60
Higher Education Institution Website Template (College/University Category) 0831

Higher Education Institution Website Template (College/University Category) 0831 Practical Collection Yiyou template

An EyouCMS website template designed specifically for universities and colleges. Its professional and dignified design is ideal for showcasing institutional profiles, departmental structures, admissions information, and campus culture. This template helps universities attract students online and enhance their brand image. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS (Ey...
👁 46
(PC + WAP) Home Textiles – Knitted Bedding and Daily Care Products – Corporate Website (PBootCMS Template) – Download – 0712

(PC + WAP) Home Textiles – Knitted Bedding and Daily Care Products – Corporate Website (PBootCMS Template) – Download – 0712 Practical Collection pbootcms Template

A PbootCMS template specifically designed for home textile, bedding, and daily household goods companies, supporting access via both PC and WAP devices. Its cozy, lifestyle-oriented design is ideal for showcasing products such as bedding, towels, and everyday household items. This template helps home goods companies quickly establish a branded official website and expand their online retail or wholesale distribution channels. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin...
👁 50
jQuery AJAX Tutorial: Integrating with Web Forms (Frontend + Backend PHP)

jQuery AJAX Tutorial: Integrating with Web Forms (Frontend + Backend PHP) Language Notes JavaScript

Communicating with the server is easy using jQuery's ajax functions, and the form can send data to the server. Using them together allows for dynamically loaded and more interactive web pages. Below is a simple tutorial showing how to use jQuery's ajax functions to send form data to the server. Introduce jQuery library Introduce jQuery library into the page so that you can use jQuery's aja...
👁 115
Responsive bilingual (Chinese/English) building materials exhibition and sales website template – 0175

Responsive bilingual (Chinese/English) building materials exhibition and sales website template – 0175 Practical Collection Yiyou template

This EyouCMS responsive bilingual (Chinese/English) template is ideal for the building materials exhibition and sales industry. Its international, professional design style enables effective presentation of building materials products, export advantages, project cases, and brand image. The multilingual support facilitates brand promotion for building materials enterprises in global markets. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 61