Q:

What does CAST function do?

I encountered these statements in the SQL and I don't understand what will be the output using CAST function?
These are the statements:

cast(date_var - 19000000 as DATE) + 1  as integer

will this output the next day of date_var?

cast(substr('date_var',1,6) || '01' as integer) - 10000

I'm more confused on what will be the output on this?

A:

CAST or CONVERT convert explicit a value form one data type to another.
SQL Syntax 1:
CONVERT( datatype, expression [, style] )

SQL Syntax 2:
CAST( expression AS datatype )

Parameters:
        expression
Any expression of any type.
datatype
The new data type. This parameter is not a expression.
style
A integer value for compatible with the MS SQL Server.
Escape Syntax:
{fn CONVERT( expression, datatype )}

Return Type:
        definite with the parameter datatype.
Examples:
SELECT convert( varchar(30), price )
SELECT convert( nvarchar(30), now(), 102)
SELECT {fn convert( {fn now()}, nvarchar(30))}
SELECT cast( price as varchar(30)

Source 

A:

The CAST() function converts a value of any type into a value that has a specified type. 
The target type can be any one of the following types: 
BINARY, CHAR, DATE, DATETIME, TIME,DECIMAL, SIGNED, UNSIGNED.
syntax:- CAST(expr AS type)
ex:-1
mysql> SELECT NOW();
+---------------------+
| NOW()               |
+---------------------+
| 2017-02-06 10:49:00 |
+---------------------+
1 row in set (0.00 sec)

mysql> SELECT CAST(NOW() as DATE);
 +---------------------+
| CAST(NOW() as DATE) |
+---------------------+
| 2017-02-06          |
+---------------------+ 
1 row in set (0.00 sec)

ex:-2
mysql> SELECT CAST(-1 as signed);
       +--------------------+
       | CAST(-1 as signed) |
       +--------------------+
       |                 -1 |
       +--------------------+
      1 row in set (0.00 sec)

 mysql> SELECT CAST(-1 as unsigned);
       +----------------------+
       | CAST(-1 as unsigned) |
       +----------------------+
       | 18446744073709551615 |
       +----------------------+
     1 row in set (0.00 sec)

