• MYSQL中,CAST函数的使用规则


    CAST函数语法规则是:Cast(字段名 as 转换的类型 ),其中类型可以为:

    CHAR[(N)] 字符型
    DATE 日期型
    DATETIME 日期和时间型
    DECIMAL float型
    SIGNED int
    TIME 时间型

    实例1:

    表table1
    
    date:2015-11-03 15:31:26
    
    select cast(date as signed) as date from  table1;
    

    结果如下:

    date:20151103153126
    
    select cast(date as char) as date from  table1;
    

    结果如下:

    date:2015-11-03 15:31:26
    

     实例2:

    select cast(date as datetime) as date from  table1;
    

    结果如下:

    date:2015-11-03 15:31:26
    

     实例3:

    select cast(date as date) as date from  table1;
    

    结果如下:

    date:2015-11-03
    

    实例4:

    select cast(date as time) as date from  table1;
    

     实例4:

    select cast(date as time) as date from  table1;
    

    结果如下:

    date:15:31:26
    

    这里date对应日期,time对应时间

    实例5:

    表table2
    num:20
    select cast(num as decimal(10, 2)) as num from table2
    

    结果如下:

    num:20.00
    
  • 相关阅读:
    学无止境,我爱python
    Flask目录
    Django目录
    前端目录
    python目录
    MySQL目录
    Oracle与Sql server的区别
    Git
    restful规范
    Django 解决跨域问题(写入到中间件中)
  • 原文地址:https://www.cnblogs.com/bao-bei/p/13437618.html
Copyright © 2020-2023  润新知