How to use the original Guid in the SQL statement instead of the little endian one?

血红的双手。 提交于 2019-12-07 07:35:10

问题


I know we can

INSERT INTO "Table1" VALUES(X'57A00F3015310D4081AD4ADEF3EBDB5E');

But this little endian format is difficult to compare to the original Guid

300FA057-3115-400D-81AD-4ADEF3EBDB5E

How to use the original Guid in the SQL statement instead of the little endian one?


回答1:


If you want to easily compare to the original without converting then store it as text. It'll take more storage space and will be slower to read/write/compare, but it'll be more human readable.




回答2:


I'm having similar frustrations and am experimenting with a querying tool to do conversion for me.

For now I get by with something like the below.

select quote(SomeGuid) from MyTable where name = 'Some Name'

Which returns

X'12A0E85D8175514DA792EC3D9A8EFCF7'

Formatting the original guid and comparing to the above:

5DE8A01275814D51A792EC3D9A8EFCF7 -- original no dashes, uppercase 12A0E85D8175514DA792EC3D9A8EFCF7 -- quote(Guid)

I can get away with querying a partial Guid for filtering purposes.

Note % on the right side too - value is quoted

select * from MyTable where quote(SomeGuid) like '%A792EC3D9A8EFCF7%'



回答3:


Try this:

INSERT INTO [Table1] ([UID]) VALUES ('{57A00F30-1531-0D40-81AD-4ADEF3EBDB5E}');

I always do in this way, didn't find any problem.



来源:https://stackoverflow.com/questions/5066392/how-to-use-the-original-guid-in-the-sql-statement-instead-of-the-little-endian-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!