dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Intermediate
Dec 17, 2019

Using CAST for Explicit Conversion in MySQL

MySQL allows you to explicitly convert a number to a string with the help of CAST function. The example below illustrates how to use it.

SELECT 55.5 AS NUMBER, CAST(55.5 AS CHAR) AS CAST_NUMBER;

Output:

+-----------------------+
| NUMBER  | CAST_NUMBER |
+-----------------------+
|    55.5 | 55.5        |
+-----------------------+

You can observe that the first column is a number whereas the second column has a string value that is also left aligned.

There is also the CONCAT function which implicitly converts NUMBER to STRING when used.

M S Sridhar
 
Thanks for your registration, follow us on our social networks to keep up-to-date