在mysql中从右边开始的3个字符后向字符串添加空格

时间:2022-06-12 04:48:10

I have a requirement where at first I need to remove all space from a string, then put a space after 3 characters started from right.

我有一个要求,首先我需要从字符串中删除所有空格,然后在从右边开始3个字符后放置一个空格。

I have removed the spaces but putting space after certain characters is not happening.

我删除了空格,但在某些字符没有发生后放置空格。

IE:

IE:

AX1098 
AX1 098  

2 个解决方案

#1


6  

SELECT INSERT('AX1098', 4, 0, ' ');

http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_insert

http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_insert

To update all rows:

要更新所有行:

UPDATE YOURTABLE
SET YOURCOL = INSERT(YOURCOL, 4, 0, ' ');

#2


0  

If strings have different length then:

如果字符串长度不同,则:

update t set F = INSERT(F,LENGTH(F)-2,0,' ');

#1


6  

SELECT INSERT('AX1098', 4, 0, ' ');

http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_insert

http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_insert

To update all rows:

要更新所有行:

UPDATE YOURTABLE
SET YOURCOL = INSERT(YOURCOL, 4, 0, ' ');

#2


0  

If strings have different length then:

如果字符串长度不同,则:

update t set F = INSERT(F,LENGTH(F)-2,0,' ');