Nested CAST not working

2019-04-27 23:33发布

Why is a nested cast NOT working in MySQL? (It does using SQL Server)

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

SQLFiddle Example

2条回答
2楼-- · 2019-04-28 00:21

This query is working on the concept of nested cast.

cast(sum(cast(Column_name int )+ cast(Column_name as int)) as bigint) as payment from table_name

查看更多
来,给爷笑一个
3楼-- · 2019-04-28 00:32

According to 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]

So, just follow the manual:

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

or

SELECT CAST(CAST(myColumn AS DECIMAL(5,2)) AS UNSIGNED) FROM myTable
查看更多
登录 后发表回答