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

 About This Book

 Introduction of SQL

 MySQL Introduction and Installation

 Introduction of MySQL Programs

 PHP Programs and MySQL Server

 Perl Programs and MySQL Servers

 Java Programs and MySQL Servers

 Datatypes and Data Literals

 Operations and Expressions

 Character Strings and Bit Strings

Commonly Used Functions

 Flow Control Functions

 Character String Functions

 Numeric Value Functions

 Date and Time Functions

 JSON Document Functions

 XML Document Functions

 Spatial Data Functions

Cast Function

 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

 Locks Used in MySQL

 Defining and Calling Stored Procedures

 Variables, Loops and Cursors Used in Stored Procedures

 System, User-Defined and Stored Procedure Variables

 MySQL Server Administration

 Storage Engines in MySQL Server

 InnoDB Storage Engine - Primary and Secondary Indexes

 Performance Tuning and Optimization

 Bulk Changes on Large Tables

 MySQL Server on macOS

 Installing MySQL Server on Linux

 Connection, Performance and Second Instance on Linux

 Archived Tutorials

 References

 Full Version in PDF/EPUB