数据库版本 oracle 10.2.0.1
第一条sql
drop table v_11;
create table v_11 as
select sum(b.amount*rate/100) amount
from pay_due_t b,document_t a,v_t c
where a.serial_number=b.serial_number
and b.currency_code=c.currency_code
and c.year=(to_char(deal_date,'yyyy'))
and c.month=to_number(to_char(deal_date,'mm'))
and deal_date between trunc(to_date('07-09-2012','mm-dd-yyyy'),'yyyy') and to_date('07-09-2012 23:59:59','mm-dd-yyyy hh24:mi:ss')
;
select sum(amount) from v_11;
第二条
select sum(b.amount*rate/100) amount
from pay_due_t b,document_t a,v_t c
where a.serial_number=b.serial_number
and b.currency_code=c.currency_code
and year=(to_char(deal_date,'yyyy'))
and month=to_number(to_char(deal_date,'mm'))
and deal_date between trunc(to_date('07-09-2012','mm-dd-yyyy'),'yyyy') and to_date('07-09-2012 23:59:59','mm-dd-yyyy hh24:mi:ss');
其中 v_t.year v_t.month 都是varchar2类型
两者看起来运行结果是一样的,实际却不一样的
但因为数据类型的不同 to_number的使用导致了错误结果
and c.month=to_number(to_char(deal_date,'mm'))
修改成
and c.month=to_char(to_number(to_char(deal_date,'mm')))
结果就一致了
阅读(957) | 评论(0) | 转发(0) |