dpp3047 2016-08-25 09:23
浏览 55

如何按格式错误的列选择行

I have got a very old database, where someone didn't keep valid format for data. So in my Column I have got values like that:

in column is   1234567890             expected   1234567890
in column is   12-345-678-9-0 foo     expected   1234567890
in column is   bar 1234-567-890       expected   1234567890
in column is   12-34567-foobar-890    expected   1234567890
etc.

I mean, there is a number (always 10 digits), with some other characters in random places.

I have got in my variable $number the integer value of 10 digits.

I want to do some query like SELECT * FROM table WHERE Column = $number, but I want to match all rows that has got this $number, if I would clean my column to right format.

I have no idea, how can I do this :(

  • 写回答

1条回答 默认 最新

  • duanrang9348 2016-08-25 09:35
    关注

    To convert data from this alphanumerical column I see two possibilities:

    1. Read all entries from the table (via php, as you already specified as tag), change it with a regular expression $newValue = preg_replace('/\D/', '', $oldValue); and update the database entry with that value.

    or

    1. Use a user defined function like MySQL UDF RegExp to do that directly with a MySQL update statement.
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入