我的数据库中有一个包含透视表的存储过程。

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'),但结果相同。

您能帮我得到正确的列名和相应的值吗

最佳答案

我不知道您是否仍然遇到此问题,最近我遇到了同样的事情,这可以帮助我获取ResultSet中的所有列:

ResultSetMetaData rsmd = result.getMetaData();
int columnCount = rsmd.getColumnCount();

// The column count starts from 1
for (int j = 1; j <= columnCount; j++) {
    System.out.println(rsmd.getColumnName(j) + " - " + rsmd.getColumnType(j) + " - " + rsmd.getColumnTypeName(j));
}


再见!

09-27 15:04