zoukankan      html  css  js  c++  java
  • mysql中将一个数据类型转换成另外的数据类型?mysql中cast函数的使用?

    需求描述:

      今天在看mysql的函数,提到了通过cast函数将一个数据类型值转换为特定类型的结果值.

      在此记录下.将一个表达式转换为特定精度的小数.

    操作过程:

    1.查看6/4的结果

    mysql> select 6/4;
    +--------+
    | 6/4    |
    +--------+
    | 1.5000 |
    +--------+
    1 row in set (0.00 sec)

     备注:通过查询结果可以知道,结果是精确到小数点后4位的.

    2.通过cast函数,将这个结果转换为decimal数据类型,并且指定精确到小数点后1位

    mysql> select cast(6/4 as decimal(3,1));
    +---------------------------+
    | cast(6/4 as decimal(3,1)) |
    +---------------------------+
    |                       1.5 |
    +---------------------------+
    1 row in set (0.00 sec)

    备注:通过结果可以知道,目前呢,已经转为decimal数据类型.

    另:decimal(3,1)表示最多3位数字,精确到小数点后1位,执行四舍五入.

    官方文档参考:

    CAST(expr AS type)
    
    The CAST() function takes an expression of any type and produces a result value of the specified type, similar to CONVERT().
    For more information, see the description of CONVERT(). CAST() is standard SQL syntax.

    文档创建时间:2018年6月26日15:38:27

  • 相关阅读:
    php5使用docker工具安装mcrypt
    golang 三目运算的实现
    图片壁纸
    使用golang实现栈(stack)
    Qt 异常处理 QT_TRY和QT_CATCH
    OpenCV 实现图片HDR功能
    OpenCV HDR合成
    OpenCV .直方图均衡 CLAHE算法学习
    OpenCV 直方图均衡化原理
    OpenCV 直方图绘制以及直方图均衡化
  • 原文地址:https://www.cnblogs.com/chuanzhang053/p/9229497.html
Copyright © 2011-2022 走看看