
我们可以使用FIELD()函数来查找作为记录存储在MySQL表列中的字符串的索引位置。为了演示它,我们使用名为“websites”的表,其中包含以下数据
mysql> Select * from websites; +----+---------------+------------------------+ | Id | Purpose | Webaddress | +----+---------------+------------------------+ | 1 | For tutorials | www.tutorialspoint.com | | 2 | For searching | www.google.co.in | | 3 | For email | www.gmail.com | +----+---------------+------------------------+ 3 rows in set (0.00 sec)
现在,假设我们想从存储在该表的“用途”和“网址”列中的记录中的字符串中找出特定字符串(如“电子邮件”)的索引号,则以下内容查询就可以了 -
mysql> Select FIELD('For email', purpose, webaddress) From websites;
+----------------------------------------+
| FIELD('For email', purpose, webaddress)|
+----------------------------------------+
| 0 |
| 0 |
| 1 |
+----------------------------------------+
3 rows in set (0.00 sec)上面的结果集显示“For email”字符串位于第三行的第一个索引处。
mysql> Select FIELD('www.tutorialspoint.com', purpose, web address) From websites;
+------------------------------------------------------+
| FIELD('www.tutorialspoint.com', purpose, web address)|
+------------------------------------------------------+
| 2 |
| 0 |
| 0 |
+------------------------------------------------------+
3 rows in set (0.00 sec)上面的结果集显示“www.tutorialspoint.com”字符串位于第一行的第二个索引处。
以上就是我们如何找到作为记录存储在MySQL表列中的字符串的索引位置?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号