Replace some content of a field in mysql, mysqlreplace
Recently, a friend mentioned how to use SQL to delete some content in a field. So I wrote this article and briefly noted it:
The test table is as follows:
Copy codeThe Code is as follows:
Create table 'T '(
'Id' int (10) unsigned not null AUTO_INCREMENT,
'Domain 'tinytext,
Primary key ('id ')
) ENGINE = MyISAM AUTO_INCREMENT = 2 default charset = utf8
Insert test content:
Copy codeThe Code is as follows:
Insert into t (domain) VALUES ('j054, j020, mc032, her302 ')
Replace table content:
Copy codeThe Code is as follows:
UPDATE t SET domain = (REPLACE (domain, ', her302', '') WHERE id = 1
View replacement results
Mysql batch replaces some content of a field
Set @ prefix = 'img. youacom /';
Select concat (@ prefix, SUBSTRING_INDEX (imgurl, '/',-1) imgurl from ly_img;
How to Implement the replace command in foxpro, replace part of the data in Field 1, such
Set ① field name to A; ② to replace all "Chinese" to "Chinese" in field A of all records in the current table; then:
Replace a with strtran (A, "Chinese", "China") ALL
See VF help:
① REPLACE FieldName1 WITH eExpression1 [ADDITIVE] [, FieldName2 WITH eExpression2 [ADDITIVE]... [Scope] [FOR lExpression1] [WHILE lExpression2] [IN nWorkArea | cTableAlias]
Set the field FieldName1 [, FieldName2] In the table specified by nWorkArea | or cTableAlias... replace the content [respectively] with the expression eExpression1 [eExpression2]... [ADDITIVE] is only used for the remarks field, indicating that the content of the eExpression is appended to the end of the remarks field; [Scope] specifies the replacement record range, it can be ALL or NEXT nRecords or REST or RECORD nRecordNumber. The default value is the current RECORD (NEXT 1). [FOR lExpression1], [WHILE lExpression2] specifies the conditions FOR replacement, within the range of [Scope], the REPLACE operation is performed as long as the results of lExpression1 and lExpression2 are true.
② STRTRAN (c1, c2 [, c3] [, n1] [, n2])
Replace c2 in c1 with c3, starting from n1 c2 in c1, and continuously replacing n2. C1, c2, and c3 can be character expressions or remarks fields. The default value of c3 is a null string, the default value of n1 is 1, and the default value of n2 is all c2 starting from n1.