如何將一個儲存的 MD5 字串轉換成 MySQL 中的一個十進位制值?
你可以連用 conv() 函式和 cast() 函式將十六進位制轉換為十進位制值。
注意 − MD5 採用十六進位制
我們先建立一個表 −
mysql> create table DemoTable ( Password text ); Query OK, 0 rows affected (0.60 sec)
使用 insert 命令向表中插入一些記錄 −
mysql> insert into DemoTable values("a5391e96f8d48a62e8c85381df108e98");
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable values("ea7a32d2dc5bb793af262dcb6ea1a54d");
Query OK, 1 row affected (0.18 sec)使用 select 語句顯示錶中的所有記錄 −
mysql> select *from DemoTable;
這將產生以下輸出 −
+----------------------------------+ | Password | +----------------------------------+ | a5391e96f8d48a62e8c85381df108e98 | | ea7a32d2dc5bb793af262dcb6ea1a54d | +----------------------------------+ 2 rows in set (0.00 sec)
以下是將儲存的 md5 字串轉換為 MySQL 中十進位制值的查詢 −
mysql> select cast(conv(substr(Password, 1, 16), 16, 10) as decimal(65))*18446744073709551616 + cast(conv(substr(Password, 17, 16), 16, 10) as decimal(65)) AS DecimalValue from DemoTable;
這將產生以下輸出 −
+-----------------------------------------+ | DecimalValue | +-----------------------------------------+ | 219619200658969319114298942978912194200 | | 311673842057003455136843080376797734221 | +-----------------------------------------+ 2 rows in set (0.00 sec)
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP