Given the examples you cited, there is no difference other than syntax . The two functions are described in the same page in the MySql documentation .
The explanation of the documentation for the existence of both is that CONVERT is specified by default ODBC while CAST is specified by default ANSI SQL . There is no evidence of performance differences or anything like that.
When used with a different syntax, CONVERT can convert a character set into another ( CONVERT... USING...
). The CAST
command does not have this option.
Reflecting:
What I find interesting is that a database engine does not have to support ODBC syntax to be accessed via ODBC.
See, for example, the ODBC documentation for the CONVERT function itself . It shows the following example:
If an application specifies the following command:
SELECT EMPNO FROM EMPLOYEES WHERE {fn CONVERT(EMPNO,SQL_CHAR)} LIKE '1%'
An Oracle driver translates to:
SELECT EMPNO FROM EMPLOYEES WHERE to_char(EMPNO) LIKE '1%'
Now, if the driver needs to translate the command, CONVERT would not need to be supported by the MySql engine; only ODBC Driver implementations for MySql are required to handle this function.
My conclusion to the MySql engine supporting both functions is that CAST
is limited to the ANSI SQL standard, while CONVERT
can take variations for the benefit of the MySql developer. For now, your only variation seems to be the USING
syntax to set the conversion of a character set to another (even though this syntax is provided in obscure SQL-99).
To support this conclusion, we can also study the CONVERT function of MS SQL Server and Oracle. In MS SQL Server , CONVERT may receive a third parameter to specify a format or date style , and can be used for the same purpose as CAST. And in Oracle CONVERT is exclusively for converting a character set in another (separating the parameters with a comma without the using in the syntax.
In other words, in addition to the common and multicompatible CAST , DBMSs also support variations of CONVERT to grace their unique developers.
>