Home Sql Mysql-example MySQL Converting Expression



MySQL Converting Expression
Posted on: February 4, 2009 at 12:00 AM
MySQL Convert function is used to convert the data from one type to another type. The CONVERT () function helps you to take a value of one type and result a value of another type.

MySQL Converting Expression

     

MySQL Convert function is used to convert the data from one type to another type. The CONVERT () function helps you to take a value of one type and result a value of another type.

This example illustrates how to use the cast function and operator in mysql.

The Tutorial illustrate an example from 'MySQL Converting Expression'. To understand and grasp the example we use a query CAST() that accept data of one type and produced the value in another type.

 

 

 

Query

 

SELECT CONVERT('abc' USING utf8);

 

Output

 

+---------------------------+
| CONVERT('abc' USING utf8) |
+---------------------------+
| abc                       |
+---------------------------+

 

CONVERT(image USING binary) :This is used to Convert image in to binary as image 

Query

 

SELECT 'image' LIKE CONVERT(image USING binary) FROM pictures;

 

Output

 

+------------------------------------------+
| 'image' LIKE CONVERT(image USING binary) |
+------------------------------------------+
| 0                                        |
| 0                                        |
| 0                                        |
+------------------------------------------+

 

CAST('19' AS DECIMAL(5,2)) : This is used to Cast in to integer to decimal.

Query
 
SELECT CAST('19' AS DECIMAL(5,2)) as result;
 
Output

 

+--------+
| result |
+--------+
| 19.00  |
+--------+
 

CAST(NOW()) : This is used to Cast the current Date.

Query

 

SELECT CAST(NOW() AS DATE);

 

Output

 

+---------------------+
| CAST(NOW() AS DATE) |
+---------------------+
| 2009-01-16          |
+---------------------+

 

CAST(NOW() ) : Cast the current Date in to integer.

Query

 

SELECT CAST(NOW() AS SIGNED);

 

Output

 

+-----------------------+
| CAST(NOW() AS SIGNED) |
+-----------------------+
| 2009                  |
+-----------------------+

 

Related Tags for MySQL Converting Expression:
sqlmysqlcdatafunctionconvertfuniohelpsedtypevalueunctoenotuseulresultpefromnompsesfuncssuatmykisandrtvassthalundonomo


More Tutorials from this section

Ask Questions?    Discuss: MySQL Converting Expression  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.