在数据处理的过程中发现,有需要A 表的 id(Number) 和B表的source_code(Char)类型的关联数据;
后来发现 有类似 20150619120238-145 这种格式的source_code也不是科学记数法的数据;
select a.id,
nvl(tem.cancel_amount,0.00) as am
from a
left join (select a1.source_code,b.cancel_amount,b.cancel_date
from (select det.id,det.source_code
from det
where source_type = 6
and return_type = 3) a1
inner join (select relative_id as relative_id,
sum(cancel_amount) as cancel_amount,
max(create_date) as cancel_date
from detail
where source_order_type = 2
group by relative_id) b on a1.id = b.relative_id) tem on to_char(a.id) =
tem.source_code
where 1 = 1
and a.TOTAL_DATE >= to_date('2016-05','yyyy-mm')
and a.TOTAL_DATE <= to_date('2016-08','yyyy-mm')
order by a.TOTAL_DATE,a.id
单独查询tem和 a都是正确的 。错误就在关联处没有加上 to_char;总是报告“无效数字“的错误;
经过同事讨论发现:
select to_number(20150619120238-145) from dual; -------------oracle数据库会自动做减法; 运行没问题 当做了一个表达式 减法运算;
select to_number(‘’20150619120238-145‘’) from dual;---------------单引号的字符串强制类型转换,报错 :无效数字;
oracle就是有这么多规矩 ,还需要学习的东西有很多……
原文链接:https://www.f2er.com/oracle/212988.html