MySQL 如何替换特定表中特定字段中的所有 NULL 值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4629202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I replace all my NULL values in a particular field in a particular table?
提问by Valerie
I've looked all over the internet for my answer, and perhaps I'm just doing things wrong. I have a column in my MySQL table that I need to replace all the NULL values with a text string in my SQL Query using phpMyAdmin. I don't want the output to come out that way, I want to actually replace the null values with the text string.
我在互联网上寻找答案,也许我只是做错了。我的 MySQL 表中有一个列,我需要使用 phpMyAdmin 将 SQL 查询中的所有 NULL 值替换为文本字符串。我不希望输出以这种方式出现,我想用文本字符串实际替换空值。
I've tried
我试过了
UPDATE `tablename` SET fieldname = replace (fieldname, "", "textstring")
I've read up on
我已经阅读了
SELECT ISNULL(field,"replacetext)
But this only shows the output, but doesn't actually replace it in the table.
但这仅显示输出,而实际上并未在表中替换它。
I can't figure this out, and I've wasted so much time trying to find an answer.
我无法弄清楚这一点,我浪费了太多时间试图找到答案。
回答by Nylon Smile
update tablename set fieldname = "textstring" where fieldname is null;
回答by Raj
Have you tried
你有没有尝试过
UPDATE `tablename` SET fieldname = '' where fieldname is null