gpt4 book ai didi

sql - sql查询中%%%的含义?

转载 作者:行者123 更新时间:2023-12-04 21:07:54 24 4
gpt4 key购买 nike

我熟悉这种查询:

select * from tableA where foo like '%bar%'

但是今天我在一些遗留代码中遇到了三个相邻的百分比符号,如下所示:
select * from tableA where foo like '%%%'

当 foo 是字符串类型(varchar 等)时,这个查询在 mssql 和 oracle 上似乎都有效,但当 foo 是数字时它会失败。

知道这意味着什么吗?

编辑:抱歉原始问题中的错字,查询使用 LIKE 运算符。

最佳答案

结果在 mysql 中它匹配everthing:

mysql> create database foo;
Query OK, 1 row affected (0.06 sec)

mysql> use foo;
Database changed

mysql> create table foo ( bar char(20) );
Query OK, 0 rows affected (0.06 sec)

mysql> desc foo;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| bar | char(20) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
1 row in set (0.00 sec)

mysql> insert into foo values ('endwith%');
Query OK, 1 row affected (0.05 sec)

mysql> insert into foo values ('%startwith');
Query OK, 1 row affected (0.00 sec)

mysql> insert into foo values ('cont%ins');
Query OK, 1 row affected (0.00 sec)

mysql> insert into foo values ('doesnotcontain');
Query OK, 1 row affected (0.00 sec)

mysql> select * from foo where bar like '%%%';
+----------------+
| bar |
+----------------+
| endwith% |
| %startwith |
| cont%ins |
| doesnotcontain |
+----------------+
4 rows in set (0.00 sec)

关于sql - sql查询中%%%的含义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2139512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com