Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在MySQL中比较“大于”和“小于”字符串安全吗?_Mysql_Comparison_String Comparison - Fatal编程技术网

在MySQL中比较“大于”和“小于”字符串安全吗?

在MySQL中比较“大于”和“小于”字符串安全吗?,mysql,comparison,string-comparison,Mysql,Comparison,String Comparison,MySQL 5.1.41-3ubuntu12.10-log似乎通过使用>大于和

MySQL 5.1.41-3ubuntu12.10-log似乎通过使用>大于和<小于给出了字符串比较的可预测结果:

select "a" > "a", "a" > "b", "b" > "a", "ab" > "aa", "ab" > "aabbbb";
+-----------+-----------+-----------+-------------+-----------------+
| "a" > "a" | "a" > "b" | "b" > "a" | "ab" > "aa" | "ab" > "aabbbb" |
+-----------+-----------+-----------+-------------+-----------------+
|         0 |         0 |         1 |           1 |               1 | 
+-----------+-----------+-----------+-------------+-----------------+
而且似乎还利用钥匙:

explain select productcode from products where productcode < 'no'; 
+----+-------------+----------+-------+-----------------+------+---------+------+------+--------------------------+
| id | select_type | table    | type  | possible_keys   | key  | key_len | ref  | rows | Extra                    |
+----+-------------+----------+-------+-----------------+------+---------+------+------+--------------------------+
|  1 | SIMPLE      | products | range | productcode,ppp | ppp  | 34      | NULL |  432 | Using where; Using index |
+----+-------------+----------+-------+-----------------+------+---------+------+------+--------------------------+

这似乎没有记录在案-这是可靠的跨平台功能吗?

这些比较很常见。我确信跨平台支持通过ascii值或其他类似的编码来比较字符串。对不起,我没有任何资源来备份它。这可能就是它比较字符串进行排序的方式。我希望这是一个主要功能。

我认为存在一些问题,您可以在这里查看文档以了解一些详细信息:

如果您的字段也有空值,还应查看空安全比较运算符:

例如:

mysql> select "a" > "a ", "A" > "a" , "aB"  > "ab" , "a" >= NULL , "a" <=> NULL ;
+------------+-----------+--------------+-------------+--------------+
| "a" > "a " | "A" > "a" | "aB"  > "ab" | "a" >= NULL | "a" <=> NULL |
+------------+-----------+--------------+-------------+--------------+
|          0 |         0 |            0 |        NULL |            0 |
+------------+-----------+--------------+-------------+--------------+

第一个链接实际上没有关于比较这样的字符串的任何信息。