Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In SQL, what does a leading "X" mean when defining a string?

Tags:

sql

mysql

I'm working on a project where I was given a SQL file to generate a database and some sample values. One of the fields (HTMLContent) is type blob and the values being inserted into it are in the form X'<long-string-of-numbers-and-letters>'.

What does the leading 'X' signify?

CREATE TABLE `advertDOM` (
  `id` int(11) NOT NULL,
  `HTMLContent` blob COMMENT 'DOM data to be displayed on screen',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `advertDOM` (`id`, `HTMLContent`)
VALUES
    (1,X'3C646976206964203D2022636F6E74656E742220636C617373203D202266756C6C73637265656E2D6C616E647363617065223E0A20203C646976206964203D202277312D636F6E7461696E6572223E0A202020207B77317D0A20203C2F6469763E0A3C2F6469763E'),
    (2,X'3C646976206964203D2022636F6E74656E742220636C617373203D202274776F2D77696E646F772D6C616E647363617065223E0A20203C646976206964203D202277312D636F6E7461696E6572223E0A202020207B77317D0A20203C2F6469763E0A20203C646976206964203D202277322D636F6E7461696E6572223E0A202020207B77327D0A20203C2F6469763E0A3C2F6469763E'),
    (3,X'3C646976206964203D2022636F6E74656E742220636C617373203D202266756C6C73637265656E2D706F727472616974223E0A20203C646976206964203D202277312D636F6E7461696E6572223E0A202020207B77317D0A20203C2F6469763E0A3C2F6469763E'),
    (4,X'3C646976206964203D2022636F6E74656E742220636C617373203D202274776F2D77696E646F772D706F727472616974223E0A20203C646976206964203D202277312D636F6E7461696E6572223E0A202020207B77317D0A20203C2F6469763E0A20203C646976206964203D202277322D636F6E7461696E6572223E0A202020207B77327D0A20203C2F6469763E0A3C2F6469763E');
like image 669
Nathan Wailes Avatar asked Nov 18 '25 08:11

Nathan Wailes


1 Answers

From the MySQL documentation:

Hexadecimal literal values are written using X'val' or 0xval notation, where val contains hexadecimal digits (0..9, A..F). Lettercase of the digits and of any leading X does not matter. A leading 0x is case-sensitive and cannot be written as 0X.

So, you are just looking at hexadecimal string literals. You can see based on your table definition that these strings are being stored as binary, in a BLOB column.

like image 195
Tim Biegeleisen Avatar answered Nov 20 '25 20:11

Tim Biegeleisen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!