mysql – 嵌套的CAST无法正常工作

前端之家收集整理的这篇文章主要介绍了mysql – 嵌套的CAST无法正常工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

为什么嵌套的转换不适用于MySQL? (它确实使用sql Server)

select cast(cast(myColumn as decimal(5,2)) as int) from myTable 

SQLFiddle Example

最佳答案
根据the manual

CAST(expr AS type) […]

CONVERT(expr,type) […]

The type can be one of the following values:

  • BINARY[(N)]

  • CHAR[(N)]

  • DATE

  • DATETIME

  • DECIMAL[(M[,D])]

  • SIGNED [INTEGER]

  • TIME

  • UNSIGNED [INTEGER]

所以,只需按照手册:

SELECT CAST(CAST(myColumn AS DECIMAL(5,2)) AS SIGNED) FROM myTable

要么

SELECT CAST(CAST(myColumn AS DECIMAL(5,2)) AS UNSIGNED) FROM myTable
原文链接:https://www.f2er.com/mysql/433733.html

猜你在找的MySQL相关文章