I have a field 开发者_开发百科"my_data" with strings like these :
XX-12-XXXX
12-XX-2000
XX-XX-2000
XX-XX-XXXX
and I'd like to change every XX and XXXX with, respectively, 00 and 0000
How can I do it with a MySql query?
Use the REPLACE
function:
UPDATE myTable
SET my_data = REPLACE(my_date, 'XX', '00')
Note:
I am using XX
as this will also replace XXXX
, but not single occurrences of X
.
You cam use REPLACE()
function:
UPDATE table
SET my_data = REPLACE(my_data, 'X', '0');
SELECT REPLACE(my_data, 'X', '0') AS myData
FROM table;
精彩评论