在SQLite中与HEX()相反? [英] Opposite of HEX() in SQLite?
问题描述
我有这个简单的查询,它返回一串guid为十六进制字符串:
I have this simple query that returns a bunch of guids as hexadecimal strings:
SELECT HEX(guid) FROM table;
其中之一是例如 43F4124307108902B7A919F4D4D0770D
。然后想象我想用这个GUID获得记录,所以我写了一个这样的查询:
One of them is for instance 43F4124307108902B7A919F4D4D0770D
. Then imagine I want to get the record with this guid, so I write a query like this:
SELECT * FROM table WHERE guid = '43F4124307108902B7A919F4D4D0770D';
当然,这是行不通的,因为字符串被直接解释为blob而不是转换为它是十六进制值。我查看了这里,但找不到任何看起来像一个采用十六进制字符串并将其转换为blob的方法。
Of course, this will not work, since the string is directly interpreted as a blob and not converted to it's hex value. I looked here, but couldn't find anything that looks like a method that takes a hexadecimal string and converts it to a blob.
推荐答案
在编写问题时,我找到了答案。我只需要在字符串前添加一个X.像这样:
While writing the question I found the answer. I simply had to add an X before the string. Like this:
SELECT * FROM table WHERE guid = X'43F4124307108902B7A919F4D4D0770D';
我想我应该发布这个问题,因为非类似问题可以回答这个问题。我所寻找的不是一种功能,而是一种文字,当我意识到这一点时,我很快找到了答案 here 。
I figured I should post the question anyway, since non of the "Similar Questions" answers this. What I was looking for was not a function, but a literal and when I realized this I quickly found the answer here.
这篇关于在SQLite中与HEX()相反?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!