1

我的数据库中有一个存储过程,其中包含一个数据透视语句。

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 是
我尝试使用ars1.getString('SERIES_XML')但结果相同的 ColumnIndex。

你能帮我得到正确的列名和对应的值吗?

4

1 回答 1

0

我不知道你是否还有这个问题,最近我有同样的事情,这有助于我获取 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));
}

再见!

于 2018-11-08T20:37:56.650 回答