Home Tutorial Php Sql Mysql converting expression

 
 

Share on Google+Share on Google+
Mysql converting expression
Posted on: December 9, 2010 at 12:00 AM
Advertisement
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                  |
+-----------------------+

 

Advertisement

Related Tags for Mysql converting expression:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 9, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com