我做了以下測試......
1)用一些數據創建表格:
create table test(col varchar(10));
insert into test values ('abc'), ('dbe');
2)使用相同的過濾器(但不同的字符)的行選擇數:
select count(*)
from test
where col like '%B%' -- note the uppercase
;
得到了以下結果:
+----------+
| count(*) |
+----------+
| 2 |
+----------+
1 row in set
3)嘗試您的更新:
update test
set col = replace(col, 'B', '') -- note the uppercase
where col like '%B%' -- note the uppercase
;
並得到了這個結果:
Query OK, 0 rows affected (0.01 sec)
Rows matched: 2 Changed: 0 Warnings: 0
在我的情況下,創建表時使用的默認字符集和排序規則。默認字符集是'latin1'和整理'latin1_swedish_ci'。請注意排序規則末尾的ci
....它表示不區分大小寫。因此,LIKE
篩選器進行了不區分大小寫的搜索,找到了2行,但REPLACE
函數(可在文檔中看到)是區分大小寫的。可能與我的情況一樣,更新發現的行數與select中的行數相同,但由於REPLACE
上的案例限制,數據更新較少。
如果這是你的問題,你不能只運行兩個更新,一個是大寫的情況下,一個是小寫的?我會嘗試開發一個更新的解決方案...
的docs關於REPLACE(str, from_str, to_str)
功能:
Returns the string str with all occurrences of the string from_str replaced by the string to_str. REPLACE() performs a case-sensitive match when searching for from_str.
docs的有關操作者LIKE
:
The following two statements illustrate that string comparisons are not case sensitive unless one of the operands is a case sensitive (uses a case-sensitive collation or is a binary string):
第一個例子:
mysql> SELECT 'abc' LIKE 'ABC';
-> 1
第二個例子:
mysql> SELECT 'abc' LIKE _latin1 'ABC' COLLATE latin1_general_cs;
-> 0
注意排序結束時的cs
。這意味着區分大小寫。
你有沒有嘗試使用SELECT子句中的WHERE條件: 'WHERE POST_CONTENT IN(SELECT DISTINCT POST_CONTENT FROM le_wp_posts WHERE POST_CONTENT LIKE '%A%')' – Pat
@pat'#1093 - 你無法指定目標表'le_wp_posts'在FROM子句中進行更新'是UPDATE的結果le_wp_posts SET post_content = REPLACE(post_content,'','')WHERE post_content IN(SELECT不同的post_content FROM le_wp_posts WHERE post_content LIKE' Â%')' – rickyduck
http:// stackoverflow。com/questions/45494/mysql-error-1093 -cant-specified-target-table-for-update-in-from-clause - 檢查此事 – Pat