我有一個填充10k行數據的數據庫表。大部分這些行在特定列中都有空值。如何將這個空值替換爲例如字符串列的空字符串?如何從表格列中刪除空值?
我在尋找的最簡單辦法做到這一點,因爲這個操作只需要進行一次。
我曾嘗試:
UPDATE tablename set mycolumn='' where mycolumn is null;
這給了我下面的錯誤:
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect.
我不是數據庫管理員,所以我不能禁用安全模式。
UPDATE tablename set mycolumn=''
where Id in (SELECT Id FROM tablename where mycolumn is null);
這給了我下面的錯誤:
Error Code: 1093. You can't specify target table 'tablename' for update in FROM clause.
注:
在上面的例子中我已經取代了真正的表名和字段名佔位符。
[使用列級別WHERE子句更新多個列中的所有SQL NULL值?](http://stackoverflow.com/questions/3938958/update-all-sql-null-values-in-multiple-columns -using-column-level-where-clause) –
做相反的事情,用NULL替換空字符串! – jarlh
是的,要求很奇怪。爲什麼你想用空白的字符替換NULL值? –