The actual java class (using dbms_output.put_line to log because I will call it from SQL, use System.out.println if called from java):SQL> CREATE OR REPLACE 2 AND COMPILE JAVA SOURCE NAMED "ArrayDemo" 3 as 4 import java.sql.*; 5 import oracle.sql.*; 6 import oracle.jdbc.driver.*; 7 8 public class ArrayDemo { 9 10 private static void log(String s) throws SQLException { 11 PreparedStatement ps = 12 new OracleDriver().defaultConnection().prepareStatement 13 ( "begin dbms_output.put_line(:x); end;" ); 14 ps.setString(1, s); 15 ps.execute(); 16 ps.close(); 17 } 18 19 public static void getArray() throws SQLException { 20 21 Connection conn = new OracleDriver().defaultConnection(); 22 23 OracleCallableStatement cs = 24 (OracleCallableStatement)conn.prepareCall 25 ( "begin p_sql_type(?); end;" ); 26 cs.registerOutParameter(1, OracleTypes.ARRAY, "T_TABLE"); 27 cs.execute(); 28 ARRAY array_to_pass = cs.getARRAY(1); 29 30 /*showing content*/ 31 Datum[] elements = array_to_pass.getOracleArray(); 32 33 for (int i=0;i<elements.length;i++){ 34 Object[] element = ((STRUCT) elements[i]).getAttributes(); 35 String value = (String)element[0]; 36 log("array(" + i + ").val=" + value); 37 } 38 } 39 } 40 /Java created让我们称之为:SQL> CREATE OR REPLACE 2 PROCEDURE show_java_calling_plsql 3 AS LANGUAGE JAVA 4 NAME 'ArrayDemo.getArray()'; 5 /Procedure createdSQL> EXEC show_java_calling_plsql;array(0).val=aarray(1).val=b 这篇关于使用 JDBC 从存储过程中获取 Oracle 表类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!