MySQL:如何查詢具有特殊字元的 value 並用 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)
以下是找到 value 並用 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)
廣告