/*
71.HAMMING_DISTANCE
HAMMING_DISTANCE(<left_hand_side>, <right_hand_side>)
汉明距离是一个概念,它表示两个(相同长度)字对应位不同的数量,我们以d(x,y)表示两个字x,y之间的汉明距离。
对两个字符串进行异或运算,并统计结果为1的个数,那么这个数就是汉明距离。
Integer和binary参数按位比较,而字符串参数按字节比较。
当两个参数长度不一致,返回-1,当两个参数有null值,返回null。
*/
SELECT HAMMING_DISTANCE('abc', 'ca') FROM DUMMY; SELECT HAMMING_DISTANCE('abc', null) FROM DUMMY; SELECT HAMMING_DISTANCE('abc', 'abc') FROM DUMMY; SELECT HAMMING_DISTANCE(200, 300) FROM DUMMY; SELECT HAMMING_DISTANCE(300, 300) FROM DUMMY; SELECT HAMMING_DISTANCE(TO_BINARY('abc'), TO_BINARY('cab')) FROM DUMMY;
/*
72.HASH_MD5
HASH_MD5(<argument> [,...])
HASH_SHA256(<argument> [,...])
Returns a 32 byte VARBINARY hash value
*/
SELECT HASH_MD5(TO_BINARY('database')) FROM DUMMY; --两个语句返回相同值,将字符串连接再转换 SELECT HASH_MD5(to_binary('abcd'), TO_BINARY('efg')) FROM DUMMY; SELECT HASH_MD5(TO_BINARY('abc'), TO_BINARY('defg')) FROM DUMMY; SELECT HASH_SHA256 (TO_BINARY('database')) FROM DUMMY; --返回相同值 SELECT HASH_SHA256(to_binary('abcd'), TO_BINARY('efg')) FROM DUMMY; SELECT HASH_SHA256(TO_BINARY('abc'), TO_BINARY('defg')) FROM DUMMY;
/*
73.HEXTOBIN
HEXTOBIN(<hexadecimal_string>)
HEXTOBIN returns a VARBINARY value
HEXTONUM(<string> [, -1])
Converts a hexadecimal value to a BIGINT string value.
-1,表示返回负数
<string>:VARCHAR,NVARCHAR类型,不超过16个字符
*/
SELECT HEXTOBIN ('608da975') FROM DUMMY; SELECT HEXTOBIN ('FFF') FROM DUMMY; --不存在 --SELECT HEXTONUM('FFFFFFFFFFFFFFFFF') FROM DUMMY;
/*
74.HOUR
HOUR(<time>)
返回小时
*/
SELECT HOUR ('12:34:56') FROM DUMMY;