首先,在JDBC中:
Oracle的JDBC不直接支持一次执行多条语句。一种解决办法如下:
String str = "BEGIN";
str += " OPEN ? FOR SELECT * FROM EMP;";
str += " OPEN ? FOR SELECT * FROM EMP;";
str += " END;";
CallableStatement cs = m_dbConn.prepareCall(str);
cs.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
cs.registerOutParameter(2, oracle.jdbc.OracleTypes.CURSOR);
cs.execute();
//Get the rows from each resultset returned by the anonymous block
ResultSet resultSet = (ResultSet)cs.getObject(1);
while (resultSet.next())
{
System.out.println("RS1:"+resultSet.getInt(1));
}
resultSet = (ResultSet)cs.getObject(2);
while (resultSet.next())
{
System.out.println("RS2:"+resultSet.getInt(1));
}
str += " OPEN ? FOR SELECT * FROM EMP;";
str += " OPEN ? FOR SELECT * FROM EMP;";
str += " END;";
CallableStatement cs = m_dbConn.prepareCall(str);
cs.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
cs.registerOutParameter(2, oracle.jdbc.OracleTypes.CURSOR);
cs.execute();
//Get the rows from each resultset returned by the anonymous block
ResultSet resultSet = (ResultSet)cs.getObject(1);
while (resultSet.next())
{
System.out.println("RS1:"+resultSet.getInt(1));
}
resultSet = (ResultSet)cs.getObject(2);
while (resultSet.next())
{
System.out.println("RS2:"+resultSet.getInt(1));
}
在.NET Framework中,使用OracleClient执行多条SQL估计也会存在同样的问题。
这篇文章有相应的介绍:
http://www.cnblogs.com/attraction/archive/2004/06/05/13665.aspx