建站经验

如何使用SQL批量替换数据库特定字段中部分特定数据

建站经验 51源码 2023-01-06 人阅读

1、替换数据库特定字段中部分特定数据的SQL语句
SQL语句:update 表名 set 字段名= replace(字段名,‘原字符串’,需要替换成的字符串’)

以将表exam_major中的字段pos2019中的数据 50 替换成 100 为例:

在查询中运行update exam_major set pos2019 = replace (pos2019, ‘50’, ‘100’)

2、批量将数据库中特定字段中的NULL替换为0
SQL语句:update 表名 set 表名.字段名=ifnull( 表名.字段名,0)

以表exam_major中的字段first_discipline为例:

在查询中运行update exam_major set exam_major.first_discipline=ifnull( exam_major.first_discipline,0)
————————————————
版权声明:本文为CSDN博主「刘增昆」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zengkunliu/article/details/105302475

版权声明:文章搜集于网络,如有侵权请联系本站,转载请说明出处:https://www.51yma.cn/yunying/exp/1003.html
文章来源:https://blog.csdn.net/zengkunliu/article/details/105302475
标签