MySQL:如何查找特殊字符的值并替换为NULL?
为此,请使用以下语法中的SET yourColumnName = NULL −
update yourTableName
set yourColumnName=NULL
where yourColumnName=yourValue;
首先,让我们创建一张表−
mysql> create table DemoTable1914
(
Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
Code varchar(20)
)AUTO_INCREMENT=1001;
Query OK, 0 rows affected (0.00 sec)
使用insert命令向表中插入一些记录−
mysql> insert into DemoTable1914(Code) values('John101');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1914(Code) values('234David');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1914(Code) values('100_Mike');
Query OK, 1 row affected (0.00 sec)
使用select语句显示表中的所有记录−
mysql> select * from DemoTable1914;
这将产生以下输出−
+------+----------+
| Id | Code |
+------+----------+
| 1001 | John101 |
| 1002 | 234David |
| 1003 | 100_Mike |
+------+----------+
3 rows in set (0.00 sec)
以下是查找值并替换为NULL的查询语句
mysql> update DemoTable1914
set Code=NULL
where Code='100_Mike';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
让我们再次检查表中的记录−
mysql> select * from DemoTable1914;
这将产生以下输出−
+------+----------+
| Id | Code |
+------+----------+
| 1001 | John101 |
| 1002 | 234David |
| 1003 | NULL |
+------+----------+
3 rows in set (0.00 sec)
阅读更多:MySQL 教程