CAST(expr AS type), CONVERT(expr,type), CONVERT(expr USING transcoding_name) : CAST « Cast Functions Operators « MySQL Tutorial

MySQL Tutorial
1. Introduction
2. Select Query
3. Database
4. Table
5. Table Join
6. Subquery
7. Insert Update Delete
8. Logic Operator
9. View
10. Data Types
11. Procedure Function
12. Cursor
13. Trigger
14. Date Time Functions
15. Comparison Functions Operators
16. Aggregate Functions
17. Cast Functions Operators
18. Control Flow Functions
19. Encryption Compression Functions
20. Information Functions
21. Math Numeric Functions
22. Miscellaneous Functions
23. String Functions
24. Regular Expressions
25. Data Dictionary
26. MySQL Utilities
27. Privilege
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
MySQL Tutorial » Cast Functions Operators » CAST 
17. 3. 1. CAST(expr AS type), CONVERT(expr,type), CONVERT(expr USING transcoding_name)

The CAST() and CONVERT() functions take a value of one type and produce a value of another type.

The type can be one of the following values:

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

CONVERT() with USING is used to convert data between different character sets.

17. 3. CAST
17. 3. 1. CAST(expr AS type), CONVERT(expr,type), CONVERT(expr USING transcoding_name)
17. 3. 2. Converting the string 'abc' in the default character set to the corresponding string in the utf8 character set:
17. 3. 3. Convert blob column to char type
17. 3. 4. The cast functions are useful when you want to create a column with a specific type in a CREATE ... SELECT statement:
17. 3. 5. CAST() is useful for sorting ENUM columns in lexical order.
17. 3. 6. CAST() also changes the result if you use it as part of a more complex expression such as CONCAT('Date: ',CAST(NOW() AS DATE)).
17. 3. 7. SELECT CAST(1 AS UNSIGNED) - 2.0;
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.