SELECT 0x0a+0;
返回 10。
为什么
SELECT 0x0a;
什么都不返回?
是否有关于如何编写正确的十六进制文字的图表。任何官方引用相关mysql手册将不胜感激。
最佳答案
MySQL documentation这一点很清楚:
In numeric contexts, hexadecimal values act like integers (64-bit precision). In string contexts, they act like binary strings, where each pair of hex digits is converted to a character:
第一种情况是数字上下文,因此它被视为数字。
第二个是无上下文的,相当于字符串上下文(至少在这种情况下)。 ASCII 值 10 的字符是换行符,您不会在输出中看到它。
关于使用 0x 表示法的 MySql 十六进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20670714/