오라클과 프로그램간에 배열을 어떻게 주고 받을 것이지
고민해 보신 분들이 계실 줄 압니다.
며칠간 시간이 나서 이리저리 찾아보니까..다음처럼 결과물이 나왔네요...
사실 몇 달 전부터 한 번 봐야 쓰겄다 했는데...이제사 조금 감을 잡았습니다.
실제적으로 프로젝트에 적용해본 적은 없고..테스트로 해 본 내용입니다.
필요한 상황에 맞게 응용을 해보시면 될 성 싶습니다.
제가 능력많아..떡하니 이렇게 작품을 내놓으면 좋겠지만......
애석하게도.. http://asktom.oracle.com/pls/ask/f?p=4950:1: 에서 자료참조를 했습니다.
1. Java Stored Procedure "ArrayDemo" 생성
create or replace
and compile java source named "ArrayDemo"
as
import java.io.*;
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
public class ArrayDemo
{
public static void passArray() throws SQLException
{
Connection conn = new OracleDriver().defaultConnection();
int intArray[] = { 1,2,3,4,5,6 };
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "NUM_ARRAY",
conn);
ARRAY array_to_pass = new ARRAY( descriptor, conn, intArray );
OraclePreparedStatement ps =
(OraclePreparedStatement)conn.prepareStatement( "begin give_me_an_array
(:x); end;" );
ps.setARRAY( 1, array_to_pass );
ps.execute();
}
}
/
Java created.
2. 사용할 Array(or TYPE) 생성
create or replace type NUM_ARRAY as table of number;
/
Type created.
3. Array 출력시키는 Procedure 생성
create or replace procedure give_me_an_array( p_array in num_array )
as
begin
for i in 1 .. p_array.count
loop
dbms_output.put_line( p_array(i) );
end loop;
end;
/
Procedure created.
4. java source를 호출하는 Procedure 생성
create or replace procedure show_java_calling_plsql
as language java
name 'ArrayDemo.passArray()';
/
Procedure created.
5. Procedure "give_me_an_array"에서 출력하는 내용을 보기 위한 명령어
set serveroutput on
6. show_java_calling_plsql 실행
exec show_java_calling_plsql
결과>
1
2
3
4
5
6
고민해 보신 분들이 계실 줄 압니다.
며칠간 시간이 나서 이리저리 찾아보니까..다음처럼 결과물이 나왔네요...
사실 몇 달 전부터 한 번 봐야 쓰겄다 했는데...이제사 조금 감을 잡았습니다.
실제적으로 프로젝트에 적용해본 적은 없고..테스트로 해 본 내용입니다.
필요한 상황에 맞게 응용을 해보시면 될 성 싶습니다.
제가 능력많아..떡하니 이렇게 작품을 내놓으면 좋겠지만......
애석하게도.. http://asktom.oracle.com/pls/ask/f?p=4950:1: 에서 자료참조를 했습니다.
1. Java Stored Procedure "ArrayDemo" 생성
create or replace
and compile java source named "ArrayDemo"
as
import java.io.*;
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
public class ArrayDemo
{
public static void passArray() throws SQLException
{
Connection conn = new OracleDriver().defaultConnection();
int intArray[] = { 1,2,3,4,5,6 };
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "NUM_ARRAY",
conn);
ARRAY array_to_pass = new ARRAY( descriptor, conn, intArray );
OraclePreparedStatement ps =
(OraclePreparedStatement)conn.prepareStatement( "begin give_me_an_array
(:x); end;" );
ps.setARRAY( 1, array_to_pass );
ps.execute();
}
}
/
Java created.
2. 사용할 Array(or TYPE) 생성
create or replace type NUM_ARRAY as table of number;
/
Type created.
3. Array 출력시키는 Procedure 생성
create or replace procedure give_me_an_array( p_array in num_array )
as
begin
for i in 1 .. p_array.count
loop
dbms_output.put_line( p_array(i) );
end loop;
end;
/
Procedure created.
4. java source를 호출하는 Procedure 생성
create or replace procedure show_java_calling_plsql
as language java
name 'ArrayDemo.passArray()';
/
Procedure created.
5. Procedure "give_me_an_array"에서 출력하는 내용을 보기 위한 명령어
set serveroutput on
6. show_java_calling_plsql 실행
exec show_java_calling_plsql
결과>
1
2
3
4
5
6
[이 게시물은 관리자님에 의해 2011-10-31 16:47:36 Oracle에서 이동 됨]
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8130 | 9년 전 | 474 | ||
| 8129 |
|
9년 전 | 628 | |
| 8128 | 9년 전 | 504 | ||
| 8127 |
|
9년 전 | 564 | |
| 8126 | 9년 전 | 493 | ||
| 8125 | 9년 전 | 751 | ||
| 8124 |
|
9년 전 | 485 | |
| 8123 | 9년 전 | 474 | ||
| 8122 | 9년 전 | 410 | ||
| 8121 | 9년 전 | 515 | ||
| 8120 | 9년 전 | 448 | ||
| 8119 | 9년 전 | 525 | ||
| 8118 |
|
9년 전 | 613 | |
| 8117 |
|
9년 전 | 384 | |
| 8116 |
PASKRAN
|
9년 전 | 456 | |
| 8115 | 9년 전 | 445 | ||
| 8114 |
kiplayer
|
9년 전 | 587 | |
| 8113 | 9년 전 | 423 | ||
| 8112 |
|
9년 전 | 539 | |
| 8111 | 9년 전 | 391 | ||
| 8110 | 9년 전 | 430 | ||
| 8109 | 9년 전 | 343 | ||
| 8108 |
|
9년 전 | 528 | |
| 8107 |
|
9년 전 | 416 | |
| 8106 |
|
9년 전 | 414 | |
| 8105 | 9년 전 | 457 | ||
| 8104 |
|
9년 전 | 412 | |
| 8103 |
|
9년 전 | 412 | |
| 8102 |
|
9년 전 | 371 | |
| 8101 |
snshero
|
9년 전 | 759 | |
| 8100 | 9년 전 | 819 | ||
| 8099 | 9년 전 | 785 | ||
| 8098 | 9년 전 | 696 | ||
| 8097 | 9년 전 | 486 | ||
| 8096 | 9년 전 | 686 | ||
| 8095 | 9년 전 | 814 | ||
| 8094 | 9년 전 | 489 | ||
| 8093 | 9년 전 | 780 | ||
| 8092 | 9년 전 | 741 | ||
| 8091 | 9년 전 | 1130 | ||
| 8090 | 9년 전 | 743 | ||
| 8089 | 9년 전 | 945 | ||
| 8088 | 9년 전 | 620 | ||
| 8087 | 9년 전 | 730 | ||
| 8086 | 9년 전 | 495 | ||
| 8085 | 9년 전 | 462 | ||
| 8084 | 9년 전 | 601 | ||
| 8083 | 9년 전 | 571 | ||
| 8082 | 9년 전 | 742 | ||
| 8081 | 9년 전 | 455 | ||
| 8080 | 9년 전 | 543 | ||
| 8079 | 9년 전 | 496 | ||
| 8078 | 9년 전 | 424 | ||
| 8077 | 9년 전 | 503 | ||
| 8076 | 9년 전 | 388 | ||
| 8075 | 9년 전 | 404 | ||
| 8074 | 9년 전 | 372 | ||
| 8073 | 9년 전 | 425 | ||
| 8072 | 9년 전 | 411 | ||
| 8071 |
o1o111
|
9년 전 | 861 | |
| 8070 | 9년 전 | 380 | ||
| 8069 | 9년 전 | 307 | ||
| 8068 | 9년 전 | 573 | ||
| 8067 | 9년 전 | 377 | ||
| 8066 | 9년 전 | 407 | ||
| 8065 | 9년 전 | 354 | ||
| 8064 | 9년 전 | 338 | ||
| 8063 | 9년 전 | 302 | ||
| 8062 | 9년 전 | 290 | ||
| 8061 | 9년 전 | 335 | ||
| 8060 | 9년 전 | 358 | ||
| 8059 | 9년 전 | 295 | ||
| 8058 | 9년 전 | 231 | ||
| 8057 | 9년 전 | 361 | ||
| 8056 | 9년 전 | 288 | ||
| 8055 | 9년 전 | 320 | ||
| 8054 | 9년 전 | 339 | ||
| 8053 | 9년 전 | 381 | ||
| 8052 | 9년 전 | 264 | ||
| 8051 | 9년 전 | 309 | ||
| 8050 | 9년 전 | 375 | ||
| 8049 | 9년 전 | 302 | ||
| 8048 | 9년 전 | 407 | ||
| 8047 | 9년 전 | 338 | ||
| 8046 | 9년 전 | 268 | ||
| 8045 | 9년 전 | 239 | ||
| 8044 | 9년 전 | 312 | ||
| 8043 | 9년 전 | 254 | ||
| 8042 | 9년 전 | 269 | ||
| 8041 | 9년 전 | 313 | ||
| 8040 | 9년 전 | 240 | ||
| 8039 | 9년 전 | 300 | ||
| 8038 | 9년 전 | 252 | ||
| 8037 | 9년 전 | 372 | ||
| 8036 | 9년 전 | 455 | ||
| 8035 | 9년 전 | 409 | ||
| 8034 | 9년 전 | 370 | ||
| 8033 | 9년 전 | 329 | ||
| 8032 | 9년 전 | 387 | ||
| 8031 | 9년 전 | 319 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기