[英]MySQL replace a character with a space
WOW... Using MySQL, is there a way to replace the third "-" from the left in the following timestamp: 哇...使用MySQL,有没有办法在以下时间戳中替换左侧的第三个“-”:
2012-06-05-23:48:10 2012-06-05-23:48:10
You'd think after an hour of searching I would have found something.. 您认为经过一个小时的搜索,我会发现一些东西。
The literal replace operation that you describe is probably beyond the abilities of pure mySQL - it has regex capabilities , but only for matching. 您描述的文字替换操作可能超出了纯mySQL的能力-它具有regex功能 ,但仅用于匹配。
However, one workaround comes to mind: 但是,想到一种解决方法:
Convert the field into a DATETIME field using STR_TO_DATE()
使用STR_TO_DATE()
将字段转换为DATETIME字段
then output it using a custom format using DATE_FORMAT()
然后使用DATE_FORMAT()
使用自定义格式输出
that said, storing the date as a native DATETIME
field in the first place would be a good idea anyway. 也就是说,首先将日期存储为本地DATETIME
字段将是一个好主意。
MySQL is a relational database management system; MySQL是一个关系数据库管理系统。 it's not for manipulating data. 它不是用于处理数据。
Instead you would use a programing or scripting language like php to query the database, pull the data into a string, change it, and update the databse. 取而代之的是,您将使用诸如php之类的编程语言或脚本语言来查询数据库,将数据提取为字符串,对其进行更改并更新数据库。 Edit: I'm told that this is possible, but as another user stated there's no direct solution in pure MySQL. 编辑:我被告知这是可能的,但是正如另一位用户所说,在纯MySQL中没有直接解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.