最近写项目遇到这样一个警告。我用的数据库是oracle9i
WARN [http-8088-2] JDBCExceptionReporter.logWarnings(54) | SQL Warning: 17110, SQLState: null
WARN [http-8088-2] JDBCExceptionReporter.logWarnings(55) | Warning: 执行完毕, 但带有警告
程序能够正常执行,但是。如果一次录入多条数据就报错:超出打开游标的最大数
网上有前辈说group by子句有null值。经过不懈努力终于解决问题:原来我在做sum函数的时候,没有处理空值。
我原来的sql语句是这样写的:
select pm.mouse_id as lid,
pm.monitor_year || '-' || pm.monitor_month as monitortime,
decode(pm.biotope, '01', '室内', '02', '室外') biotopes,
z.cnname as county,
pm.report_unit,
pmi1.hjs,
pmi1.xjs,
pmi1.hxs,
pmi1.hxjs,
pmi1.hms,
pmi1.scm,
pmi1.qt,
(select [ORGCODE] from dual) orgcode
from pidera_mouse pm
left join (select pmi.mouse_reference_id,
sum(decode(pmi.mouse_name, '01', pmi.mouse_num)) hjs,
sum(decode(pmi.mouse_name, '02', pmi.mouse_num)) xjs,
sum(decode(pmi.mouse_name, '03', pmi.mouse_num)) hxs,
sum(decode(pmi.mouse_name, '04', pmi.mouse_num)) hxjs,
sum(decode(pmi.mouse_name, '05', pmi.mouse_num)) hms,
sum(decode(pmi.mouse_name, '06', pmi.mouse_num)) scm,
sum(decode(pmi.mouse_name, '07', pmi.mouse_num)) qt
from pidera_mouse_info pmi
group by pmi.mouse_reference_id) pmi1
on pm.mouse_id =pmi1.mouse_reference_id
join zonecode z on pm.zonecode = z.zonecode
where pm.del_state != 1
and [ZONECODE]
and [DISTRICT]
and [BEGINDATE]
and [ENDDATE]
后来加入空值处理函数coalesce
select pm.mouse_id as lid,
pm.monitor_year || '-' || pm.monitor_month as monitortime,
decode(pm.biotope, '01', '室内', '02', '室外') biotopes,
z.cnname as county,
pm.report_unit,
coalesce(pmi1.hjs,0) hjs,
coalesce(pmi1.xjs,0) xjs,
coalesce(pmi1.hxs,0) hxs,
coalesce(pmi1.hxjs,0) hxjs,
coalesce(pmi1.hms,0) hms,
coalesce(pmi1.scm,0) scm,
coalesce(pmi1.qt,0) qt,
(select [ORGCODE] from dual) orgcode
from pidera_mouse pm
left join (select pmi.mouse_reference_id,
sum(coalesce(decode(pmi.mouse_name, '01', pmi.mouse_num),0)) hjs,
sum(coalesce(decode(pmi.mouse_name, '02', pmi.mouse_num),0)) xjs,
sum(coalesce(decode(pmi.mouse_name, '03', pmi.mouse_num),0)) hxs,
sum(coalesce(decode(pmi.mouse_name, '04', pmi.mouse_num),0)) hxjs,
sum(coalesce(decode(pmi.mouse_name, '05', pmi.mouse_num),0)) hms,
sum(coalesce(decode(pmi.mouse_name, '06', pmi.mouse_num),0)) scm,
sum(coalesce(decode(pmi.mouse_name, '07', pmi.mouse_num),0)) qt
from pidera_mouse_info pmi
group by pmi.mouse_reference_id) pmi1
on pm.mouse_id =pmi1.mouse_reference_id
join zonecode z on pm.zonecode = z.zonecode
where pm.del_state != 1
and [ZONECODE]
and [DISTRICT]
and [BEGINDATE]
and [ENDDATE]
问题解决啦!。