【发布时间】:2012-03-01 08:23:55
【问题描述】:
我的数据库中有一个包含数据透视语句的存储过程。
create or replace procedure example1(var1 OUT SYS_REFCURSOR)
is
DATE_FROM date;
DATE_TO date;
begin
DATE_TO := sysdate;
DATE_FROM := sysdate -10;
open var1 for
select *
from
( select m as MONTHS, s as SERIES, SUM(t) as N
from tablename
WHERE dateletter BETWEEN date_from AND date_to
group by m, s
ORDER BY m
)
PIVOT XML (SUM(N) as TOTALSUM for SERIES in (select distinct s from tablename where dateletter between date_from and date_to group by s));
END example1;
这可以正常工作,并且会显示类似这样的内容
Month SERIES_XML
2 oracle.jdbc.driver.ORACLESQLXML@d77ww5
现在在我的 java 类中
CallableStatement acs1;
acs1 = generalcon.con.prepareCall(getCursor);
acs1.registerOutParameter(1, OracleTypes.CURSOR);
acs1.executeQuery();
ars1 = (ResultSet) acs1.getObject(1);
while(ars1.next())
{
String ser = ars1.getString(2);
xmlst = xmlst + ser;
}
但是,ars1.getString(2) 返回一个空值,其中 1 是 ColumnIndex
我尝试了ars1.getString('SERIES_XML'),但结果相同。
请您帮我获取正确的列名和对应的值
【问题讨论】:
-
在这方面不强,但不确定你的
getCursor是否正确(它应该是一个类似于begin example1(?); end;的字符串)...这有帮助吗:enterprisedt.com/publications/oracle/result_set.html -
@JeffreyKemp 'getCursor' 很好
-
也许你应该打电话给
acs1.execute而不是executeQuery? -
@JeffreyKemp 它认为它将与返回结果集相同。从结果集中,我必须得到列!所以它不值得
-
啊,我看你是专家 :) 就我个人而言,没有经验,我会尝试使用 execute(),然后调用 acs1.getString(1) 来获取 out 参数;但是,那只是我:)