MySql教程

MySQL修改某一列的前几个字符

本文主要是介绍MySQL修改某一列的前几个字符,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

-- 用子查询的值,替换掉前4个字符,验证
SELECT
  concat( ( SELECT city_code FROM business_department WHERE id = p.city ), RIGHT ( new_code, CHAR_LENGTH( new_code ) - 4 ) )
FROM
  business_project p
ORDER BY
new_code DESC;

-- 更新
UPDATE business_project p
SET p.new_code = concat( ( SELECT city_code FROM business_department WHERE id = p.city ), RIGHT ( new_code, CHAR_LENGTH( new_code ) - 4 ) )

参考 https://www.zhihu.com/question/51964872

这篇关于MySQL修改某一列的前几个字符的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!