• <small id='f9Xpg'></small><noframes id='f9Xpg'>

      <i id='f9Xpg'><tr id='f9Xpg'><dt id='f9Xpg'><q id='f9Xpg'><span id='f9Xpg'><b id='f9Xpg'><form id='f9Xpg'><ins id='f9Xpg'></ins><ul id='f9Xpg'></ul><sub id='f9Xpg'></sub></form><legend id='f9Xpg'></legend><bdo id='f9Xpg'><pre id='f9Xpg'><center id='f9Xpg'></center></pre></bdo></b><th id='f9Xpg'></th></span></q></dt></tr></i><div id='f9Xpg'><tfoot id='f9Xpg'></tfoot><dl id='f9Xpg'><fieldset id='f9Xpg'></fieldset></dl></div>
        <legend id='f9Xpg'><style id='f9Xpg'><dir id='f9Xpg'><q id='f9Xpg'></q></dir></style></legend>
          <bdo id='f9Xpg'></bdo><ul id='f9Xpg'></ul>
        <tfoot id='f9Xpg'></tfoot>
      1. 在 mySQL 中的整个表中搜索字符串

        Search a whole table in mySQL for a string(在 mySQL 中的整个表中搜索字符串)

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

      2. <legend id='vDx2N'><style id='vDx2N'><dir id='vDx2N'><q id='vDx2N'></q></dir></style></legend>

            <tfoot id='vDx2N'></tfoot>
              <bdo id='vDx2N'></bdo><ul id='vDx2N'></ul>

                  <tbody id='vDx2N'></tbody>
              • <i id='vDx2N'><tr id='vDx2N'><dt id='vDx2N'><q id='vDx2N'><span id='vDx2N'><b id='vDx2N'><form id='vDx2N'><ins id='vDx2N'></ins><ul id='vDx2N'></ul><sub id='vDx2N'></sub></form><legend id='vDx2N'></legend><bdo id='vDx2N'><pre id='vDx2N'><center id='vDx2N'></center></pre></bdo></b><th id='vDx2N'></th></span></q></dt></tr></i><div id='vDx2N'><tfoot id='vDx2N'></tfoot><dl id='vDx2N'><fieldset id='vDx2N'></fieldset></dl></div>
                  本文介绍了在 mySQL 中的整个表中搜索字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 mySQL 中的整个表中搜索一个字符串.

                  我想搜索表的所有字段和所有条目,返回包含指定文本的每个完整条目.

                  我不知道如何轻松搜索多个字段;详情如下:

                  表是客户".它有大约 30 个字段和 800 个条目,太多了,无法在浏览器中一次全部显示.我想搜索一个名字(即玛丽"),但它可能在 shipping_name 字段billing_name 字段email字段等

                  我想在所有字段中搜索包含字符串Mary"的任何条目.这是我认为应该有效但无效的方法:

                  SELECT * FROM `clients` IN 'Mary'

                  解决方案

                  试试这个:

                  SELECT * FROM clients WHERE CONCAT(field1, '', field2, '', fieldn) LIKE "%Mary%"

                  您可能希望查看 SQL 文档以获取有关字符串运算符和正则表达式的其他信息.

                  NULL 字段可能存在一些问题,以防万一您可能想使用 IFNULL(field_i, '') 而不是 field_i>

                  区分大小写:您可以使用不区分大小写的排序规则或类似的东西:

                  ... WHERE LOWER(CONCAT(...)) LIKE LOWER("%Mary%")

                  只搜索所有字段:我相信没有办法让 SQL 查询在不明确声明要搜索的字段的情况下搜索所有字段.原因是存在关系理论数据库和操作关系数据的严格规则(例如关系代数或 codd 代数;这些是 SQL 的来源),并且理论不允许诸如只搜索所有字段"之类的事情.当然,实际行为取决于供应商的具体实现.但在一般情况下,这是不可能的.为了确保,请检查 SELECT 运算符语法(WHERE 部分,准确地说).

                  I'm trying to search a whole table in mySQL for a string.

                  I want to search all fields and all entrees of a table, returning each full entry that contains the specified text.

                  I can't figure out how to search multiple fields easily; here are the details:

                  The table is "clients". It has about 30 fields and 800 entries, too much to show all at once in a browser. I would like to search for a name (i.e. "Mary"), but it could be in the shipping_name field or the billing_name field, or the email field, etc.

                  I would like to search all fields for any entries that contain the string "Mary". This is what I think should work but doesn't:

                  SELECT * FROM `clients` IN 'Mary'
                  

                  解决方案

                  Try something like this:

                  SELECT * FROM clients WHERE CONCAT(field1, '', field2, '', fieldn) LIKE "%Mary%"
                  

                  You may want to see SQL docs for additional information on string operators and regular expressions.

                  Edit: There may be some issues with NULL fields, so just in case you may want to use IFNULL(field_i, '') instead of just field_i

                  Case sensitivity: You can use case insensitive collation or something like this:

                  ... WHERE LOWER(CONCAT(...)) LIKE LOWER("%Mary%")
                  

                  Just search all field: I believe there is no way to make an SQL-query that will search through all field without explicitly declaring field to search in. The reason is there is a theory of relational databases and strict rules for manipulating relational data (something like relational algebra or codd algebra; these are what SQL is from), and theory doesn't allow things such as "just search all fields". Of course actual behaviour depends on vendor's concrete realisation. But in common case it is not possible. To make sure, check SELECT operator syntax (WHERE section, to be precise).

                  这篇关于在 mySQL 中的整个表中搜索字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)(超出最大存储过程、函数、触发器或视图嵌套级别(限制 32))
                  How to View Oracle Stored Procedure using SQLPlus?(如何使用 SQLPlus 查看 Oracle 存储过程?)
                  How to debug stored procedure in VS 2015?(如何在 VS 2015 中调试存储过程?)
                  Set the variable result, from query(设置变量结果,来自查询)
                  What is dynamic SQL?(什么是动态 SQL?)
                  Mysql - How to quit/exit from stored procedure(Mysql - 如何退出/退出存储过程)
                    <i id='ElDcZ'><tr id='ElDcZ'><dt id='ElDcZ'><q id='ElDcZ'><span id='ElDcZ'><b id='ElDcZ'><form id='ElDcZ'><ins id='ElDcZ'></ins><ul id='ElDcZ'></ul><sub id='ElDcZ'></sub></form><legend id='ElDcZ'></legend><bdo id='ElDcZ'><pre id='ElDcZ'><center id='ElDcZ'></center></pre></bdo></b><th id='ElDcZ'></th></span></q></dt></tr></i><div id='ElDcZ'><tfoot id='ElDcZ'></tfoot><dl id='ElDcZ'><fieldset id='ElDcZ'></fieldset></dl></div>

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

                      <tbody id='ElDcZ'></tbody>
                      <bdo id='ElDcZ'></bdo><ul id='ElDcZ'></ul>
                      <legend id='ElDcZ'><style id='ElDcZ'><dir id='ElDcZ'><q id='ElDcZ'></q></dir></style></legend>
                          1. <tfoot id='ElDcZ'></tfoot>