从PL/SQL存储函数返回数组
// The name we use below, EMPARRAY, has to match the name of the // type defined in the PL/SQL Stored Function stmt.registerOutParameter( 1, OracleTypes.ARRAY,"EMPARRAY" ); stmt.executeUpdate(); // Get the ARRAY object and print the meta data assosiated with it ARRAY simpleArray = stmt.getARRAY(1); System.out.println("Array is of type " + simpleArray.getSQLTypeName()); System.out.println("Array element is of type code "+simpleArray.getBaseType()); System.out.println("Array is of length " + simpleArray.length()); // Print the contents of the array String[] values = (String[])simpleArray.getArray(); for( int i = 0; i < values.length; i++ ) System.out.println( "row " + i + " = '" + values[i] +"'" );......................
?
在上面的代码段中,可以看到 OracleCallableSatatement 用于调用 PL/SQL 存储函数。在执行 PL/SQL 存储函数前,将返回的数据类型注册为 OracleTypes.ARRAY,并且指定在数据库中定义的类型名称 (EMPARRAY)。然后执行 PL/SQL 存储函数并获得 oracle.sql.ARRAY 形式的返回值。 oracle.sql.ARRAY 类拥有的方法可以获得关于数组的详细信息,如数组类型、数组长度等。使用 oracle.sql.ARRAY 的 getArray() 方法获得数组的内容并将内容打印出来。
本文档说明了如何创建 VARRAY 并从 PL/SQL 存储函数返回数组,以及如何从 java 应用程序访问它
?
参考:http://www.oracle.com/technology/global/cn/sample_code/tech/java/codesnippet/jdbc/varray/index.html