MySQL Tutorials - Herong's Tutorial Examples - v4.46, by Herong Yang
Cast Function
Describes the CAST() function, which can be used to convert a value of any datatype to any other datatype.
"CAST(value AS type)" - Returns the casted value of the specified value as the specified type.
Examples of cast function, CastFunctions.sql:
-- CastFunctions.sql -- Copyright (c) 2005 HerongYang.com. All Rights Reserved. -- SELECT PI() = '3.141593'; SELECT CAST(PI() AS CHAR) = '3.141593'; SELECT SUBSTRING(CAST(TIME'10:20:30' AS CHAR),4,2); SELECT CAST(SUBSTRING('JAN 10, 1999',5,2) AS SIGNED) + 1;
Output:
PI() = '3.141593' 0 CAST(PI() AS CHAR) = '3.141593' 1 SUBSTRING(CAST(TIME'10:20:30' AS CHAR),4,2) 20 CAST(SUBSTRING('JAN 10, 1999',5,2) AS SIGNED) + 1 11
Table of Contents
MySQL Introduction and Installation
Introduction of MySQL Programs
Perl Programs and MySQL Servers
Java Programs and MySQL Servers
Character Strings and Bit Strings
Table Column Types for Different Types of Values
Using DDL to Create Tables and Indexes
Using DML to Insert, Update and Delete Records
Using SELECT to Query Database
Window Functions for Statistical Analysis
Use Index for Better Performance
Transaction Management and Isolation Levels
Defining and Calling Stored Procedures
Variables, Loops and Cursors Used in Stored Procedures
System, User-Defined and Stored Procedure Variables
Storage Engines in MySQL Server
InnoDB Storage Engine - Primary and Secondary Indexes
Performance Tuning and Optimization
Installing MySQL Server on Linux