操纵数据以检索特定数字

时间:2015-06-14 12:06:06

标签: sql database string oracle plsql

我有一个像这样的列的表:

Location 
19.15
19.14
19.13
18.01
18.02

我搜索了从头开始只检索2位数的函数:

Location 
19
19
19
18
18

不幸的是我还没找到解决方案。

2 个答案:

答案 0 :(得分:1)

select cast(location as int) as location
from your_table

答案 1 :(得分:1)

完全取决于数据类型。

我们可以使用SUBSTR()函数返回字符串列的前两个字符:

select substr(location, 1, 2) as location
from your_table; 

如果您希望在该点之前处理不同数量的数字,那么正则表达式函数可能会更好:

select regexp_substr(location, '([0-9]+)\.(.*)', 1, 1, 'i', 1)) as location
from your_table;   

如果location是数字,你想删除尾随小数,你可以像这样使用TRUNC():

select trunc(location) as location
from your_table;