오라클과 프로그램간에 배열을 어떻게 주고 받을 것이지
고민해 보신 분들이 계실 줄 압니다.
며칠간 시간이 나서 이리저리 찾아보니까..다음처럼 결과물이 나왔네요...
사실 몇 달 전부터 한 번 봐야 쓰겄다 했는데...이제사 조금 감을 잡았습니다.
실제적으로 프로젝트에 적용해본 적은 없고..테스트로 해 본 내용입니다.
필요한 상황에 맞게 응용을 해보시면 될 성 싶습니다.
제가 능력많아..떡하니 이렇게 작품을 내놓으면 좋겠지만......
애석하게도.. 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에서 이동 됨]
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 2330 | 16년 전 | 5069 | ||
| 2329 | 16년 전 | 2304 | ||
| 2328 | 16년 전 | 3404 | ||
| 2327 | 16년 전 | 2639 | ||
| 2326 | 16년 전 | 1557 | ||
| 2325 | 16년 전 | 5349 | ||
| 2324 | 16년 전 | 2470 | ||
| 2323 | 16년 전 | 5961 | ||
| 2322 | 16년 전 | 1938 | ||
| 2321 | 16년 전 | 4019 | ||
| 2320 | 16년 전 | 3030 | ||
| 2319 |
|
16년 전 | 2210 | |
| 2318 |
데니크레인
|
16년 전 | 2232 | |
| 2317 | 16년 전 | 4411 | ||
| 2316 | 16년 전 | 3294 | ||
| 2315 | 16년 전 | 2833 | ||
| 2314 | 16년 전 | 2960 | ||
| 2313 | 16년 전 | 2076 | ||
| 2312 | 16년 전 | 1766 | ||
| 2311 | 16년 전 | 1676 | ||
| 2310 | 16년 전 | 1396 | ||
| 2309 | 16년 전 | 1666 | ||
| 2308 | 16년 전 | 1902 | ||
| 2307 | 16년 전 | 1599 | ||
| 2306 |
|
16년 전 | 4849 | |
| 2305 | 16년 전 | 3827 | ||
| 2304 | 16년 전 | 1786 | ||
| 2303 | 16년 전 | 1533 | ||
| 2302 | 16년 전 | 2268 | ||
| 2301 | 16년 전 | 4530 | ||
| 2300 | 16년 전 | 3544 | ||
| 2299 | 16년 전 | 2576 | ||
| 2298 | 16년 전 | 4335 | ||
| 2297 | 16년 전 | 3207 | ||
| 2296 | 16년 전 | 1352 | ||
| 2295 |
|
16년 전 | 1378 | |
| 2294 |
|
16년 전 | 2039 | |
| 2293 | 16년 전 | 1886 | ||
| 2292 | 16년 전 | 2564 | ||
| 2291 | 16년 전 | 2233 | ||
| 2290 | 16년 전 | 1371 | ||
| 2289 | 16년 전 | 4392 | ||
| 2288 | 16년 전 | 1477 | ||
| 2287 | 16년 전 | 1781 | ||
| 2286 | 16년 전 | 2199 | ||
| 2285 |
|
16년 전 | 3833 | |
| 2284 |
|
16년 전 | 2729 | |
| 2283 |
|
16년 전 | 1486 | |
| 2282 | 16년 전 | 4011 | ||
| 2281 |
|
16년 전 | 1397 | |
| 2280 | 16년 전 | 1579 | ||
| 2279 | 16년 전 | 1234 | ||
| 2278 | 16년 전 | 1712 | ||
| 2277 | 16년 전 | 1612 | ||
| 2276 | 16년 전 | 1625 | ||
| 2275 | 16년 전 | 1424 | ||
| 2274 | 16년 전 | 2179 | ||
| 2273 | 16년 전 | 1819 | ||
| 2272 |
|
16년 전 | 1965 | |
| 2271 | 16년 전 | 2177 | ||
| 2270 |
a1system
|
16년 전 | 1472 | |
| 2269 | 16년 전 | 2306 | ||
| 2268 | 16년 전 | 2259 | ||
| 2267 | 16년 전 | 4534 | ||
| 2266 |
|
16년 전 | 1295 | |
| 2265 | 16년 전 | 1051 | ||
| 2264 |
잠자리똥꾸멍
|
16년 전 | 2009 | |
| 2263 |
태양의서쪽
|
16년 전 | 1972 | |
| 2262 |
태양의서쪽
|
16년 전 | 1516 | |
| 2261 |
태양의서쪽
|
16년 전 | 2041 | |
| 2260 |
|
16년 전 | 2270 | |
| 2259 | 16년 전 | 1386 | ||
| 2258 | 16년 전 | 1738 | ||
| 2257 | 16년 전 | 1921 | ||
| 2256 | 16년 전 | 1013 | ||
| 2255 | 16년 전 | 1689 | ||
| 2254 | 16년 전 | 1405 | ||
| 2253 | 16년 전 | 1913 | ||
| 2252 |
freedays
|
16년 전 | 1326 | |
| 2251 | 16년 전 | 2200 | ||
| 2250 | 16년 전 | 1879 | ||
| 2249 | 16년 전 | 5866 | ||
| 2248 | 16년 전 | 1912 | ||
| 2247 | 16년 전 | 3685 | ||
| 2246 | 16년 전 | 1467 | ||
| 2245 |
|
16년 전 | 1754 | |
| 2244 |
|
16년 전 | 2070 | |
| 2243 | 16년 전 | 2609 | ||
| 2242 | 16년 전 | 2306 | ||
| 2241 | 16년 전 | 2755 | ||
| 2240 | 16년 전 | 2991 | ||
| 2239 | 16년 전 | 3016 | ||
| 2238 |
|
16년 전 | 1820 | |
| 2237 |
|
16년 전 | 1540 | |
| 2236 |
|
16년 전 | 1416 | |
| 2235 | 16년 전 | 1725 | ||
| 2234 | 16년 전 | 1205 | ||
| 2233 | 16년 전 | 1960 | ||
| 2232 |
|
16년 전 | 1731 | |
| 2231 | 16년 전 | 1606 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기