扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
/*
drop table varray_table;
drop type num_varray;
CREATE TYPE num_varray AS VARRAY(10) OF VARCHAR2(12)
/
CREATE TABLE varray_table (col1 num_varray);
INSERT INTO varray_table VALUES (num_varray('你好', 'abc'));
select * from varray_table;
*/
import java.sql.*;
import java.math.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;
class Array1
{
public static void main(String args[]) throws Exception
{
int oracleId = CharacterSet.ZHS16GBK_CHARSET;
CharacterSet dbCharset = CharacterSet.make(oracleId);
DriverManager.registerDriver
(new oracle.jdbc.driver.OracleDriver());
Connection conn =
DriverManager.getConnection
("jdbc:oracle:thin:@10.9.200.58:1521:db01",
"mytest",
"mytest");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM varray_table");
while (rs.next()) {
ARRAY my_array = ((OracleResultSet)rs).getARRAY(1);
// return the SQL type names, integer codes,
// and lengths of the columns
System.out.println ("Array is of type " + my_array.getSQLTypeName());
System.out.println ("Array element is of typecode " + my_array.getBaseType());
System.out.println ("Array is of length " + my_array.length());
// get Array elements
String[] values = (String[]) my_array.getArray();
for (int i = 0; i < values.length; i++)
{
oracle.sql.CHAR out_value = new oracle.sql.CHAR(values[i], dbCharset);
System.out.println(">> index " + i + " = " + out_value);
}
}
rs.close();
stmt.close();
conn.close();
}
}
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者