更改 SELECT 语句中字段的类型
change the type of the field in the SELECT statement
我想更改 SELECT 语句中列的数据类型。我想要的数据类型的变化是从十进制到整数。我想舍弃数字的小数部分。
请告诉我怎么做。
使用floor()
函数。 floor(111.222)
将 return 111
。这不会对数字进行四舍五入,因此 floor(111.999)
也会 return 111
(这与 round()
的行为不同)。
By using the floor function will the data type be converted from decimal to whole number.
使用floor()
将数据转换为整数。如果您真的想更改数据类型(为什么?),您需要将投影列转换为整数:
cast(floor(111.999) as integer) as whole_num
请注意,单独转换会 舍入 输出。
SQLFiddle 演示 here.
in the condition i want to write a equality expression ... ) but Table1.id is decimal and Table2.id is whole number
在这种情况下真的没有关系。基本上 Oracle 有一种数字数据数据类型,数字。有别名(小数、整数等),但这些可以自由转换为数字。即111.000 = 111
。因此,您可以完全按照显示的方式编写连接,而无需进行数据类型转换。
您唯一需要担心的是十进制 ID 是否不是干净的整数,即 id != floor(id)
。如果 table 已正确填充(并且您没有使用其中一种浮点数据类型),这应该不是问题。
我想更改 SELECT 语句中列的数据类型。我想要的数据类型的变化是从十进制到整数。我想舍弃数字的小数部分。
请告诉我怎么做。
使用floor()
函数。 floor(111.222)
将 return 111
。这不会对数字进行四舍五入,因此 floor(111.999)
也会 return 111
(这与 round()
的行为不同)。
By using the floor function will the data type be converted from decimal to whole number.
使用floor()
将数据转换为整数。如果您真的想更改数据类型(为什么?),您需要将投影列转换为整数:
cast(floor(111.999) as integer) as whole_num
请注意,单独转换会 舍入 输出。
SQLFiddle 演示 here.
in the condition i want to write a equality expression ... ) but Table1.id is decimal and Table2.id is whole number
在这种情况下真的没有关系。基本上 Oracle 有一种数字数据数据类型,数字。有别名(小数、整数等),但这些可以自由转换为数字。即111.000 = 111
。因此,您可以完全按照显示的方式编写连接,而无需进行数据类型转换。
您唯一需要担心的是十进制 ID 是否不是干净的整数,即 id != floor(id)
。如果 table 已正确填充(并且您没有使用其中一种浮点数据类型),这应该不是问题。