dongna1593
2013-04-29 21:01
浏览 64
已采纳

在字符串中找到斜杠

In my MySQL database I have a lot of product codes in this form :

COD1234/ABC123/XXX0293

What I want to do is change that to :

COD1234 / ABC123 / XXX0293

The problem is I already have some of the codes in the correct form

So, I need to replace the slash ( / ), with [space]/[space] ... and of course, if there is more then one space, it's a problem ..

... and I know I should do this with PHP but if someone knows a Mysql way of doing this it would be really nice !

图片转代码服务由CSDN问答提供 功能建议

在我的MySQL数据库中,我有很多这种形式的产品代码: < p> COD1234 / ABC123 / XXX0293

我想要做的是将其更改为:

COD1234 / ABC123 / XXX0293

问题是我已经有了一些正确形式的代码

所以,我需要用[space] / [space]替换斜杠(/) ......当然,如果有一个以上的空间,那就是一个问题..

...我知道我应该用PHP做这个但是如果有人知道一个Mysql方式 这样做真的很棒!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

  • duanhan4763 2013-04-29 21:04
    最佳回答

    Here is one approach, phrased as a select:

    select replace(replace(ProductCodes, '/', ' / '), '  /  ', ' / ')
    

    The query string to replace for the outer replace has two spaces rather than one.

    If you want an update, then this might work:

    update x
        set ProductCode = replace(ProductCode, '/', ' / ')
        where ProductCode like '%/%' and ProductCode not like '% / %'
    

    This assumes that all the slashes have spaces or none.

    评论
    解决 无用
    打赏 举报
查看更多回答(2条)

相关推荐 更多相似问题