CREATE PACKAGE demo_pkg
AS
TYPE varchar2_array IS TABLE OV VAARCHAR2(30) INDEX BY BINARY_INTEGER;
TYPE rc IS REF CURSOR;
PROCEDURE index_by(p_owner IN VARCHAR2
, p_object_name OUT varchar2_array
, p_object_type OUT varchar2_array
, p_timestamp OUT varchar2_array);
PROCEDURE ref_cursor(p_owner IN VARCHAR2
, p_cursor IN OUT rc);
END;
/
CREATE PACKAGE BODY demo_pkg
AS
PROCEDURE index_by(p_owner IN VARCHAR2
, p_object_name OUT varchar2_array
, p_object_type OUT varchar2_array
, p_timestamp OUT varchar2_array)
IS
BEGIN
SELECT object_name, object_type, timestamp
BULK COLLECT INTO p_object_name, p_object_type, p_timestamp
FROM t
WHERE owner = p_owner;
END;
PROCEDURE ref_cursor(p_owner IN VARCHAR2
, p_cursor IN OUT rc)
IS
BEGIN
OPEN p_cursor FOR
SELECT object_name, object_type, timestamp
FROM t
WHERE owner = p_owner;
END;
END;
/
import java.sql.*;
import java.util.Date;
import oracle.jdbc.driver.*;
import oracle.sql.*;
class indexby
{
static long start = new Date().getTime();
public ststic void showElapsed(String msq)
{
long end = new Date().getTime();
System.out.println(msq + " " + (end - start) + " ms");
start = end;
}
public ststic void main(String args[]) throws Exception
{
DriverManager.registerDriver
(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci8:@ora920.us.oracle.com","scott","tiger");
showElapsed("Connected, going to prepare");
OracleCallableStatement cstmt =
(OracleCallableStatement)conn.prepareCall
("BEGIN demo_pkg.index_by(?,?,?,?); END;")
showElapsed("Prepared, going to bind");
int maxl = 15000;
int elemSqlType = OracleTypes.VARCHAR;
int elemMaxLen = 30;
cstmt.setString(1, "SYS");
cstmt.resisterIndexTableOutParameter(2, maxl, elemSqlType, elemMaxLen);
cstmt.resisterIndexTableOutParameter(3, maxl, elemSqlType, elemMaxLen);
cstmt.resisterIndexTableOutParameter(4, maxl, elemSqlType, elemMaxLen);
showElapsed("Bound, going to execute");
cstmt.execute();
Datum[] object_name = cstmt.getOraclePlsqlIndexTable(2);
Datum[] object_type = cstmt.getOraclePlsqlIndexTable(3);
Datum[] timestamp = cstmt.getOraclePlsqlIndexTable(4);
showElapsed("First Row " + object_name.length);
String data;
int i;
for (i=0;i<object_name.length;i++)
{
data = object_name[i].stringValue();
data = object_type[i].stringValue();
data = timestamp[i].stringValue();
}
showElapsed("Last Row " + i);
}
}
import java.sql.*;
import java.util.Date;
import oracle.jdbc.driver.*;
import oracle.sql.*;
class refcur
{
static long start = new Date().getTime();
public ststic void showElapsed(String msq)
{
long end = new Date().getTime();
System.out.println(msq + " " + (end - start) + " ms");
start = end;
}
public ststic void main(String args[]) throws Exception
{
DriverManager.registerDriver
(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci8:@ora920.us.oracle.com","scott","tiger");
showElapsed("Connected, going to prepare");
((OracleConnection)conn).setDefaultRowPrefetch(100);
OracleCallableStatement cstmt =
(OracleCallableStatement)conn.prepareCall
("BEGIN demo_pkg.ref_cursor(?,?); END;")
showElapsed("Prepared, going to bind");
cstmt.setString(1, "SYS");
cstmt.resisterOutParameter(2, OracleTypes.CURSOR);
showElapsed("Bound, going to execute");
cstmt.execute();
ResultSet rset = (ResultSet)cstmt.getObject(2);
if (rset.next())
showElapsed("First Row");
String data;
int i;
for (i=0;i<rset.next();i++)
{
data = rset.getString(1);
data = rset.getString(2);
data = rset.getString(3);
}
showElapsed("Last Row " + i);
}
}
대기시간 | INDEXBY | REFCUR | 차이 |
첫번째 행까지의 시간 | 825ms | 25ms | (800)ms |
마지막 행까지의 시간 | 1,375ms | 860ms | (515)ms |
모든행을 인출하는데 걸린 시간 | 2,200ms | 885ms | (1,315)ms |
- 강좌 URL : http://www.gurubee.net/lecture/3577
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.