<bdo id='Rk3xs'></bdo><ul id='Rk3xs'></ul>
    1. <small id='Rk3xs'></small><noframes id='Rk3xs'>

      <i id='Rk3xs'><tr id='Rk3xs'><dt id='Rk3xs'><q id='Rk3xs'><span id='Rk3xs'><b id='Rk3xs'><form id='Rk3xs'><ins id='Rk3xs'></ins><ul id='Rk3xs'></ul><sub id='Rk3xs'></sub></form><legend id='Rk3xs'></legend><bdo id='Rk3xs'><pre id='Rk3xs'><center id='Rk3xs'></center></pre></bdo></b><th id='Rk3xs'></th></span></q></dt></tr></i><div id='Rk3xs'><tfoot id='Rk3xs'></tfoot><dl id='Rk3xs'><fieldset id='Rk3xs'></fieldset></dl></div>
    2. <legend id='Rk3xs'><style id='Rk3xs'><dir id='Rk3xs'><q id='Rk3xs'></q></dir></style></legend>

        <tfoot id='Rk3xs'></tfoot>

        相当于explode() 在MySQL 中处理字符串

        时间:2023-08-18

          <tbody id='X6WpH'></tbody>
        <tfoot id='X6WpH'></tfoot>

        • <bdo id='X6WpH'></bdo><ul id='X6WpH'></ul>
          <legend id='X6WpH'><style id='X6WpH'><dir id='X6WpH'><q id='X6WpH'></q></dir></style></legend>
            1. <small id='X6WpH'></small><noframes id='X6WpH'>

              <i id='X6WpH'><tr id='X6WpH'><dt id='X6WpH'><q id='X6WpH'><span id='X6WpH'><b id='X6WpH'><form id='X6WpH'><ins id='X6WpH'></ins><ul id='X6WpH'></ul><sub id='X6WpH'></sub></form><legend id='X6WpH'></legend><bdo id='X6WpH'><pre id='X6WpH'><center id='X6WpH'></center></pre></bdo></b><th id='X6WpH'></th></span></q></dt></tr></i><div id='X6WpH'><tfoot id='X6WpH'></tfoot><dl id='X6WpH'><fieldset id='X6WpH'></fieldset></dl></div>

                  本文介绍了相当于explode() 在MySQL 中处理字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 MySQL 中,当另一个值 = '7 - 31' 时,我希望能够搜索 '31 - 7'.我会用什么语法来拆分 MySQL 中的字符串?在 PHP 中,我可能会使用 explode(' - ',$string) 并将它们放在一起.有没有办法在 MySQL 中做到这一点?

                  In MySQL, I want to be able to search for '31 - 7', when another value = '7 - 31'. What is the syntax that I would use to break apart strings in MySQL? In PHP, I would probably use explode(' - ',$string) and put them together. Is there a way to do this in MySQL?

                  背景:我正在处理体育比分,并想尝试比分相同(并且在同一日期)的比赛 - 每支球队的列出比分与对手的数据库记录相比是倒退的.

                  Background: I'm working with sports scores and want to try games where the scores are the same (and also on the same date) - the listed score for each team is backwards compare to their opponent's database record.

                  理想的 MySQL 调用是:

                  The ideal MySQL call would be:

                  Where opponent1.date  = opponent2.date
                    AND opponent1.score = opponent2.score
                  

                  (opponent2.score 需要是 opponent1.score 向后).

                  (opponent2.score would need to be opponent1.score backwards).

                  推荐答案

                  MYSQL 没有内置 explode() 之类的函数.但是您可以轻松地将类似的函数添加到您的数据库中,然后从php 查询.该函数将如下所示:

                  MYSQL has no explode() like function built in. But you can easily add similar function to your DB and then use it from php queries. That function will look like:

                  CREATE FUNCTION SPLIT_STRING(str VARCHAR(255), delim VARCHAR(12), pos INT)
                  RETURNS VARCHAR(255)
                  RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(str, delim, pos),
                         CHAR_LENGTH(SUBSTRING_INDEX(str, delim, pos-1)) + 1),
                         delim, '');
                  

                  用法:

                  SELECT SPLIT_STRING('apple, pear, melon', ',', 1)
                  

                  上面的例子将返回apple.我认为在 MySQL 中返回数组是不可能的,因此您必须在 pos 中明确指定要返回的事件.如果您成功使用它,请告诉我.

                  The example above will return apple. I think that it will be impossible to return array in MySQL so you must specify which occurrence to return explicitly in pos. Let me know if you succeed using it.

                  这篇关于相当于explode() 在MySQL 中处理字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:模拟 MySQL 中的滞后函数 下一篇:在 MySQL 数据库中以阿拉伯语保存数据

                  相关文章

                  最新文章

                    <small id='hBKKt'></small><noframes id='hBKKt'>

                    <legend id='hBKKt'><style id='hBKKt'><dir id='hBKKt'><q id='hBKKt'></q></dir></style></legend>
                  1. <i id='hBKKt'><tr id='hBKKt'><dt id='hBKKt'><q id='hBKKt'><span id='hBKKt'><b id='hBKKt'><form id='hBKKt'><ins id='hBKKt'></ins><ul id='hBKKt'></ul><sub id='hBKKt'></sub></form><legend id='hBKKt'></legend><bdo id='hBKKt'><pre id='hBKKt'><center id='hBKKt'></center></pre></bdo></b><th id='hBKKt'></th></span></q></dt></tr></i><div id='hBKKt'><tfoot id='hBKKt'></tfoot><dl id='hBKKt'><fieldset id='hBKKt'></fieldset></dl></div>

                      <tfoot id='hBKKt'></tfoot>

                        <bdo id='hBKKt'></bdo><ul id='hBKKt'></ul>