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


advertisement
 

Tip: Using CAST for Explicit Conversion in MySQL

MySQL allows you to explicitly convert a number to a string with the help of CAST function. See an example of how to use this feature.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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.

 

Visit the DevX Tip Bank

 





   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Thanks for your registration, follow us on our social networks to keep up-to-date