Använd java.sql.ResultSetMetaData.getColumnTypeName()
:
Oracle-inställningar :
CREATE OR REPLACE TYPE random_array IS TABLE OF VARCHAR2(42);
/
Java :
Class.forName("oracle.jdbc.OracleDriver");
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl",
"username",
"password"
);
PreparedStatement st = con.prepareStatement(
"SELECT random_array( 'a', 'b', 'c' ) AS array FROM DUAL"
);
ResultSet rs = st.executeQuery();
while( rs.next() )
{
String type = rs.getMetaData().getColumnTypeName(1);
String[] data = (String[]) rs.getArray(1).getArray();
System.out.println( type + ": " + Arrays.toString( data ) );
}
st.close();
con.close();
Utdata :
SCHEMA_NAME.RANDOM_ARRAY: [a, b, c]
Om du sedan vill gå tillbaka till Oracle och hitta typen av samlingselement kan du använda:
SELECT ELEM_TYPE_NAME,
LENGTH,
PRECISION,
SCALE
FROM ALL_COLL_TYPES
WHERE TYPE_NAME = 'RANDOM_ARRAY'
AND OWNER = 'SCHEMA_NAME';
Vilka utgångar:
ELEM_TYPE_NAME LENGTH PRECISION SCALE
-------------- ------ --------- -----
VARCHAR2 42