How would I go about inserting a space in a word using a MySQL string
function?
I have a GPS co-ordinate saved in my gps column as such
S2829.080,E2850.683
I would like the output to be :
S28 29.080,E28 50.683
Any advice much appreciated.
Thanks
SOLUTION UPDATE :
CREATE FUNCTION SPLIT_STR(
x VARCHAR(255),
delim VARCHAR(12),
pos INT
)
RETURNS VARCHAR(255)
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos),
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1),
delim, '');
SELECT CONCAT_WS(' ', LEFT(SPLIT_STR("S2829.080,E2850.683",',',1),3),MID(SPLIT_STR("S2829.080,E2850.683",',',1),4,LENGTH(SPLIT_STR("S2829.080,E2850.683",',',1)))) AS
latitude;
SELECT CONCAT_WS(' ', LEFT(SPLIT_STR("S2829.080,E2850.683",',',1),3),MID(SPLIT_STR("S2829.080,E2850.683",',',2),4,LENGTH(SPLIT_STR("S2829.080,E2850.683",',',2)))) AS
longitude;
I have since “Normalized” my database and changed the JS form by adding 2 columns
for longitude and latitude.
Thank you all
Try below :
use
concat(),left(),mid()mysql functions:Assuming your space will always be after 3 char in your column value
BTW it will not work if you storing comma separated values under single column. and that is drawback of such table schema.
You should
Normalizeyour databaseYou should make parent child table in-stead of comma separated values