Syntax\n------\n\nCAST(expr AS type)\n\nDescription\n-----------\n\nThe CAST() function takes a value of one data type and produces a value of another data type, similar to the CONVERT() function.\n\nThe type can be one of the following values:\n\n BINARY\n CHAR\n DATE\n DATETIME\n DECIMAL\n DOUBLE\n FLOAT\n INTEGER (short for SIGNED INTEGER )\n [SIGNED \\[INTEGER\\]](../../data-types/numeric-data-types/integer.md)\n [UNSIGNED \\[INTEGER\\]](../../data-types/numeric-data-types/integer.md)\n TIME\n VARCHAR\n* XMLTYPE (Available starting with MariaDB 12.3)\n\nThe main difference between CAST and CONVERT() is that CONVERT(expr,type) is ODBC syntax, while CAST(expr as type) and CONVERT(... USING ...) are SQL92 syntax.\n\nTo cast a value to a string data type while specifying the character set, use this extended syntax:\n\n``sql\n CAST(expr AS CHAR CHARACTER SET name)\n`\n\nSee the examples for casting to character sets.\n\nUsing an introducer like _utf8mb4'text' is often more efficient than CAST('text' AS CHAR CHARACTER SET utf8mb4), but CAST is necessary when converting data types (like numbers to strings) into a specific encoding. See this example, too.\n\nYou can use the CAST() function with the INTERVAL` keyword.\n\nThis introduced an incompatibility with previous versions of MariaDB, and all versions of MySQL (see the example below).\n\nExamples\n--------\n\nSELECT CAST("abc" AS BINARY);\nSELECT CAST("1" AS UNSIGNED INTEGER);\nSELECT CAST(123 AS CHAR CHARACTER SET utf8)\n\nURL: https://mariadb.com/docs/server/reference/sql-functions/string-functions/cast