Replace first instance NULL or ' ' with another value - MySQL [closed]

旧巷老猫 提交于 2019-12-25 17:19:42

问题


I'm trying to replace the first instance of a NULl or ' ' value in a column with another value. But only the first instance and nothing else.

So far I've put this together:

UPDATE table_name SET column = CONCAT(REPLACE(LEFT(column , INSTR(column , '')), '', 'new_value'), SUBSTRING(column , INSTR(column , '') +1))

I could replace all the values but I don't want that:

UPDATE table_name SET column = REPLACE (column , 'old_value', 'new_value')

回答1:


Just try using limit 1

  UPDATE table_name SET column='new_value' WHERE column='' limit 1


来源:https://stackoverflow.com/questions/20034103/replace-first-instance-null-or-with-another-value-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!