Insert mysql hex value

I created a sql database using Java, noob, when it comes to sql, but to configure and configure, I have a table that has two columns, the first of which is a large integer that grows, the second I tried to define it as char , varchar and binary, but im still not getting the desired function, let's say I try to store a 0a hexadecimal number in a char column, I get an error, I added 0x to the beginning of a, it looks like it stores, but when I print the contents it is empty or in some cases I get characters like '/' and and '?', I also tried to use sql explorer, and it gives me the same result as a table scan,

My problem is that I need to save an eight character hexadecimal string like eb8d4ee6.

Can someone please tell me how this can be done?

+4
source share
2 answers

Here's a great blog post that I always refer to to remind myself of the proper handling of hexadecimal values ​​and binary fields and outlined some performance implications.

http://www.xaprb.com/blog/2009/02/12/5-ways-to-make-hexadecimal-identifiers-perform-better-on-mysql/

+4
source

See http://dev.mysql.com/doc/refman/5.5/en/hexadecimal-literals.html

MySQL supports hexadecimal values ​​written using the X'val ', x'val' or 0xval format, where val contains the hexadecimal digits (0..9, A..F). Letter numbers do not matter. For values ​​written using the format X'val 'or x'val' val must contain an even number of digits. For values ​​written using the 0xval syntax, values ​​containing an odd number of digits are considered to have an additional beginning 0. For example, 0x0a and 0xaaa are interpreted as 0x0a and 0x0aaa.

In numeric contexts, hexadecimal values ​​act as integers (64-bit precision). In string contexts, they act like binary strings, where each pair of hexadecimal digits is converted to a character:

You should probably store the Hex value in an integer column. Then you can convert back to hex code when you select the HEX() function.

eg.

 INSERT INTO MyTable (`MyIntegerColumn`) VALUES (0xeb8d4ee6); 
+2
source

All Articles