Home Sql Mysql-example MySQL Convert



MySQL Convert
Posted on: January 20, 2009 at 12:00 AM
This section describes about the MySQL convert. It provides a way for converting the data of one type to another type.

MySQL Convert

     

This section describes about the MySQL convert. It provides a way for converting the data of one type to another type.

Syntax: 

CONVERT(expr,type)

 

 

 

 

The "type" can have the following values:

  1. BINARY[(N)]
  2. CHAR[(N)]
  3. DATE
  4. DATETIME
  5. DECIMAL[(M[,D])]
  6. SIGNED [INTEGER]
  7. TIME
  8. UNSIGNED [INTEGER]

For example, BINARY converts a string to BINARY data type.

Table: employee

CREATE TABLE `employee` ( 
`emp_id` int(11) NOT NULL auto_increment, 
`emp_name` varchar(100) character set utf8 NOT NULL, 
`emp_salary` int(11) NOT NULL, 
`emp_startDate` datetime NOT NULL, 
`dep_name` varchar(50) NOT NULL, 
PRIMARY KEY (`emp_id`) 
)

Data in the above table: (Using SELECT * FROM employee;)

In the following query we will use MySQL convert() function. 

SELECT CONVERT(emp_id,CHAR) AS Character_Emp_Id, 
CONVERT(emp_startDate,Date) AS Character_emp_Salary 
FROM employee;

Output:

Related Tags for MySQL Convert:
sqlmysqlcidedataconvertiotypevithisidfortoeitdessectionnotpeinnoconvertingmoutesprodescribesatmyisrtscrssrithbesabprono


More Tutorials from this section

Ask Questions?    Discuss: MySQL Convert  

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.