前导零不使用数字数据类型

时间:2017-12-06 10:44:59

标签: sql oracle

当我从视图中选择时,前面的零的结果会再次出现,因为

的数字数据类型。我需要没有前导零的结果。

 -------CODE----------
create table test_number_type(c1 number);

insert into test_number_type values(100.12);

insert into test_number_type values(0.12);

commit;

create or replace view  test_data_type as
select to_number(trim(leading 0 from c1)) c_num_check from test_number_type;

desc test_data_type

1 个答案:

答案 0 :(得分:3)

您的担忧完全是错误的。使用内部表示存储数字。它们不存储为字符串。所以,所有这些代表相同的数字(随后有一个警告):

0.12
.12
000000.12

需要注意的是,内部表征在规模和精确度方面可能有所不同。

如何呈现数字并不是真正取决于该列。如果要控制输出,请将值转换为字符串。函数to_char()允许您控制前导零。

相关问题