Home Tutorial Php Sql Mysql converting expression

 
 

Mysql converting expression
Posted on: December 9, 2010 at 12:00 AM
This example illustrates how to use the cast function and operator in mysql.

Mysql converting expression

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

In this example the Convert function is used to convert the data from one type to another type. The CONVERT() function is used to take a value of one type and produce a value of another type. As like Convert function the CAST() function is used to take data of one type and produced a value of another type. There are many more example of query is used in the mysql which produced result given below.

 

 

Query

 

SELECT CONVERT('abc' USING utf8);

 

Output

 

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

 

Convert image in to binary.

Query

 

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

 

Output

 

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

 

Cast in to integer to decimal.

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

 

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

Cast the current Date.

Query

 

SELECT CAST(NOW() AS DATE);

 

Output

 

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

 

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:


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.