这是一个测试用例,它明确表明 cast(nvl(col1,col2) as integer) 的输出与整数列的类型完全相同:
create table test1 (col1 binary_double, col2 binary_double, col3 integer);
insert into test1 values (1, 2, 3);
insert into test1 values (null, 3, 4);
insert into test1 values (null, null, 5);
commit;
select col1,
col2,
col3,
nvl(col1, col2) nvl_col1_col2,
cast(nvl(col1, col2) as integer) cast_nvl_col1_col2,
dump(col1) dump_col1,
dump(col2) dump_col2,
dump(col3) dump_col3,
dump(nvl(col1, col2)) dump_nvl_col1_col2,
dump(cast(nvl(col1, col2) as integer)) dump_cast_nvl_col1_col2
from test1;
COL1 COL2 COL3 NVL_COL1_COL2 CAST_NVL_COL1_COL2 DUMP_COL1 DUMP_COL2 DUMP_COL3 DUMP_NVL_COL1_COL2 DUMP_CAST_NVL_COL1_C
---------- ---------- ---------- ------------- ------------------ ----------------------------------- ----------------------------------- -------------------- ----------------------------------- --------------------
1 2 3 1 1 Typ=101 Len=8: 191,240,0,0,0,0,0,0 Typ=101 Len=8: 192,0,0,0,0,0,0,0 Typ=2 Len=2: 193,4 Typ=101 Len=8: 191,240,0,0,0,0,0,0 Typ=2 Len=2: 193,2
3 4 3 3 NULL Typ=101 Len=8: 192,8,0,0,0,0,0,0 Typ=2 Len=2: 193,5 Typ=101 Len=8: 192,8,0,0,0,0,0,0 Typ=2 Len=2: 193,4
5 NULL NULL Typ=2 Len=2: 193,6 NULL NULL