Insert seperator string into field value in MySQL
4 answers
use php function wordwrap()
to put a specific character after the number of characters. The function wordwrap()
wraps the line to new lines when it reaches a certain length.
$output = wordwrap($orNumber,3,'-',true);
Note. This function can leave white spaces at the beginning of a line. Thus, you have to trim your data to remove spaces.
You can check the mannual here PHP wordwrap ()
+2
source to share
set @chr = '000000002';
select @chr,
concat(substring(@chr,1,3),'-',substring(@chr,4,3),'-',substring(@chr,7,9)) hyphenated
Result
+-----------+-------------+
| @chr | hyphenated |
+-----------+-------------+
| 000000002 | 000-000-002 |
+-----------+-------------+
1 row in set (0.00 sec)
+1
source to share