我有一个像4.138这样的Oracle表列值 153.2809 128.113141081389尝试使用表DDL NUMBER(38,16)将这些值加载到雪花中。所以现在雪花表中的值变成4.1380000000000000 153.2809000000000000 128.1131410813890000,但是我需要将oracle中的值加载到雪花中,而不会尾随0。 如何实现呢?
答案 0 :(得分:1)
格式化固定位置的数字类型以使其不显示尾随零:
create or replace table TEST_NUMBERS (N number(38,16));
insert into TEST_NUMBERS(N) values (4.138), (153.2809), (128.113141081389);
select to_varchar(N, 'FMTM') as COMPACT_NUMBER from TEST_NUMBERS;
-- The "FM" toggles the "Fill Mode" to compact from the default, which is full.
-- The "TM" specifies using "Text Minimal".
-- It requires both Fill Mode of compact and Text Minimal set to suppress trailing
-- zeros on fixed-position numbers.
这当然仅用于显示和输出。如果您想了解规模和精度如何影响存储和计算,请在文档的此部分中进行注释:
答案 1 :(得分:0)
好吧,通常,如果您要存储不带尾随零的数据,则应按比例缩小。 NUMBER(38,3)将存储4.138,仅此而已。
,如果它只是用于显示,则只需根据https://docs.snowflake.net/manuals/sql-reference/sql-format-models.html#fixed-position-numeric-formats
更改格式字符串