Collections:
CHARSET() - Detecting Character Set Name
How to detect the character set name associated to a given character string using the CHARSET() function?
✍: FYIcenter.com
CHARSET(str) is a MySQL built-in function that
returns the character set name associated to a given character string.
A character set name refers to a set of rules
to encode a set of characters into byte sequences.
For example:
SELECT CHARSET('FYI');
-- +----------------+
-- | CHARSET('FYI') |
-- +----------------+
-- | utf8 |
-- +----------------+
SELECT CHARSET(CONVERT('FYI' USING latin1));
-- +--------------------------------------+
-- | CHARSET(CONVERT('FYI' USING latin1)) |
-- +--------------------------------------+
-- | latin1 |
-- +--------------------------------------+
CREATE TABLE MyTable (comment CHAR(80) CHARACTER SET utf8mb4);
INSERT INTO MyTable (comment) VALUES ('I like it!');
INSERT INTO MyTable (comment) VALUES ('Good job1');
SELECT comment, CHARSET(comment) FROM MyTable;
-- +------------+------------------+
-- | comment | CHARSET(comment) |
-- +------------+------------------+
-- | I like it! | utf8mb4 |
-- | Good job1 | utf8mb4 |
-- +------------+------------------+
Reference information of the CHARSET() function:
CHARSET(str): name Returns the character set name associated to a given character string. Arguments, return value and availability: str: Required. The character string to be examined. name: Return value. The character set name. Available since MySQL 4.0.
Related MySQL functions:
⇒ COERCIBILITY() - Character Collation Coercibility
⇐ CHARACTER_LENGTH() - Synonym for CHAR_LENGTH()
2025-10-24, 1627🔥, 0💬
Popular Posts:
Can Date and Time Values Be Converted into Integers in SQL Server Transact-SQL? Can date and time va...
How To Use DATEADD() Function in SQL Server Transact-SQL? DATEADD() is a very useful function for ma...
How To Generate Random Numbers with the RAND() Function in SQL Server Transact-SQL? Random numbers a...
What is dba.FYIcenter.com Website about? dba.FYIcenter.com is a Website for DBAs (database administr...
How To End a Stored Procedure Properly in SQL Server Transact-SQL? Where the end of the "CREATE PROC...