Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding space to a string after 3 characters starting from right in mysql

Tags:

sql

mysql

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.

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

IE:

AX1098 
AX1 098  
like image 919
Raul Avatar asked Jan 05 '13 05:01

Raul


1 Answers

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

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, ' ');
like image 199
Mate Avatar answered Sep 27 '22 01:09

Mate