简体   繁体   English

MySQL用空格替换字符

[英]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: 但是,想到一种解决方法:

that said, storing the date as a native DATETIME field in the first place would be a good idea anyway. 也就是说,首先将日期存储为本地DATETIME字段将是一个好主意。

For this, it makes more sense for the data to be saved using the standard but given back as the way your application would use it. 为此,使用标准保存数据更有意义,但将其作为应用程序使用它的方式返回。 This post explains what you are looking for. 这篇文章解释了您要寻找的内容。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM