开发者

Change partial string on a field

开发者 https://www.devze.com 2023-02-26 00:19 出处:网络
I have a field 开发者_开发百科\"my_data\" with strings like these : XX-12-XXXX 12-XX-2000 XX-XX-2000

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消