snippetsqlMinor
MySQL CAST vs. CONVERT
Viewed 0 times
convertmysqlcast
Problem
Let's say that I have a VARCHAR (which contains numeric data) that I want to use for a simple computation (adding 10 to it). According to the MySQL documentation on CAST functions, I could accomplish this with either a CAST or a CONVERT:
or:
What is the difference between CAST and CONVERT in this sense? Are they both really accomplishing the same thing?
SELECT (CAST(field1 AS SIGNED)) + 10
FROM myTable;or:
SELECT (CONVERT(field1,SIGNED)) + 10
FROM myTable;What is the difference between CAST and CONVERT in this sense? Are they both really accomplishing the same thing?
Solution
Convert and cast docs. Aside from the syntax I believe they can functionally be considered synonyms, even when trying to change character sets.
Context
StackExchange Database Administrators Q#12283, answer score: 2
Revisions (0)
No revisions yet.