Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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:

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?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Yes, CAST and CONVERT to the same thing, except that CONVERT allows more options, such as changing character set with USING.

share|improve this answer
1  
Is there a kind of performance difference o something like that... i meant there's must be a difference.. –  user7479 Mar 15 '12 at 22:48

Convert and cast docs. Aside from the syntax I believe they can functionally be considered synonyms, even when trying to change character sets.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.