Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

MySQL Cast

Here, you will learn about the MySQL CAST() function.

Ads

MySQL Cast

     

Here, you will learn about the MySQL CAST() function. 

CAST(): This is a function same as convert() function. Both functions are used to cast a value as a certain types. The CAST() function converts a value of one type to the other type.

Syntax:  

CAST(expr AS 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;)

Here, you will learn about the MySQL CAST() function. 

SELECT CAST(emp_startDate as Date) AS StartDate FROM employee;

Output:

Advertisements

Share on Google+Share on Google+

MySQL Cast

Posted on: January 20, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: MySQL Cast  

Post your Comment


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

Ads

 

Ads