오라클과 프로그램간에 배열을 어떻게 주고 받을 것이지
고민해 보신 분들이 계실 줄 압니다.
며칠간 시간이 나서 이리저리 찾아보니까..다음처럼 결과물이 나왔네요...
사실 몇 달 전부터 한 번 봐야 쓰겄다 했는데...이제사 조금 감을 잡았습니다.
실제적으로 프로젝트에 적용해본 적은 없고..테스트로 해 본 내용입니다.
필요한 상황에 맞게 응용을 해보시면 될 성 싶습니다.
제가 능력많아..떡하니 이렇게 작품을 내놓으면 좋겠지만......
애석하게도.. 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에서 이동 됨]
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1930 | 17년 전 | 2996 | ||
| 1929 | 17년 전 | 1873 | ||
| 1928 | 17년 전 | 3987 | ||
| 1927 | 17년 전 | 1401 | ||
| 1926 |
지엔소프트
|
17년 전 | 1118 | |
| 1925 |
보드타는찌니
|
17년 전 | 1229 | |
| 1924 |
choijinhee
|
17년 전 | 1110 | |
| 1923 | 17년 전 | 1370 | ||
| 1922 | 17년 전 | 1737 | ||
| 1921 | 17년 전 | 2335 | ||
| 1920 | 17년 전 | 2412 | ||
| 1919 | 17년 전 | 1415 | ||
| 1918 | 17년 전 | 1161 | ||
| 1917 | 17년 전 | 2430 | ||
| 1916 | 17년 전 | 2856 | ||
| 1915 |
|
17년 전 | 3224 | |
| 1914 | 17년 전 | 3166 | ||
| 1913 | 17년 전 | 2322 | ||
| 1912 | 17년 전 | 3745 | ||
| 1911 | 17년 전 | 3173 | ||
| 1910 | 17년 전 | 5494 | ||
| 1909 | 17년 전 | 2646 | ||
| 1908 | 17년 전 | 1850 | ||
| 1907 | 17년 전 | 1931 | ||
| 1906 | 17년 전 | 1767 | ||
| 1905 | 17년 전 | 1697 | ||
| 1904 | 17년 전 | 2761 | ||
| 1903 | 17년 전 | 1879 | ||
| 1902 | 17년 전 | 1569 | ||
| 1901 | 17년 전 | 2060 | ||
| 1900 |
stuartkim
|
17년 전 | 1125 | |
| 1899 | 17년 전 | 1658 | ||
| 1898 | 17년 전 | 2871 | ||
| 1897 | 17년 전 | 2110 | ||
| 1896 | 17년 전 | 1803 | ||
| 1895 | 17년 전 | 2021 | ||
| 1894 | 17년 전 | 1310 | ||
| 1893 | 17년 전 | 1701 | ||
| 1892 | 17년 전 | 1206 | ||
| 1891 | 17년 전 | 1766 | ||
| 1890 | 17년 전 | 1794 | ||
| 1889 | 17년 전 | 1034 | ||
| 1888 | 17년 전 | 3134 | ||
| 1887 | 17년 전 | 4309 | ||
| 1886 | 17년 전 | 2453 | ||
| 1885 | 17년 전 | 7455 | ||
| 1884 | 17년 전 | 3822 | ||
| 1883 | 17년 전 | 4153 | ||
| 1882 | 17년 전 | 2413 | ||
| 1881 | 17년 전 | 2877 | ||
| 1880 | 17년 전 | 3624 | ||
| 1879 | 17년 전 | 3995 | ||
| 1878 | 17년 전 | 3156 | ||
| 1877 | 17년 전 | 3140 | ||
| 1876 | 17년 전 | 3287 | ||
| 1875 | 17년 전 | 2455 | ||
| 1874 | 17년 전 | 2051 | ||
| 1873 | 17년 전 | 3099 | ||
| 1872 | 17년 전 | 3246 | ||
| 1871 | 17년 전 | 4603 | ||
| 1870 | 17년 전 | 1577 | ||
| 1869 | 17년 전 | 2609 | ||
| 1868 | 17년 전 | 2684 | ||
| 1867 | 17년 전 | 1895 | ||
| 1866 | 17년 전 | 2211 | ||
| 1865 | 17년 전 | 1823 | ||
| 1864 | 17년 전 | 2364 | ||
| 1863 | 17년 전 | 3766 | ||
| 1862 | 17년 전 | 3882 | ||
| 1861 | 17년 전 | 2076 | ||
| 1860 | 17년 전 | 1352 | ||
| 1859 | 17년 전 | 1490 | ||
| 1858 |
|
17년 전 | 1634 | |
| 1857 | 17년 전 | 1619 | ||
| 1856 |
보드타는찌니
|
17년 전 | 1378 | |
| 1855 | 17년 전 | 1522 | ||
| 1854 |
|
17년 전 | 1341 | |
| 1853 | 17년 전 | 1834 | ||
| 1852 | 17년 전 | 2740 | ||
| 1851 | 17년 전 | 1836 | ||
| 1850 |
|
17년 전 | 1383 | |
| 1849 |
|
17년 전 | 1671 | |
| 1848 |
|
17년 전 | 2318 | |
| 1847 | 17년 전 | 1939 | ||
| 1846 |
은사시나무
|
17년 전 | 1254 | |
| 1845 |
갈색야생마
|
17년 전 | 5894 | |
| 1844 |
갈색야생마
|
17년 전 | 3275 | |
| 1843 |
갈색야생마
|
17년 전 | 3172 | |
| 1842 |
갈색야생마
|
17년 전 | 2589 | |
| 1841 |
갈색야생마
|
17년 전 | 2769 | |
| 1840 |
갈색야생마
|
17년 전 | 2718 | |
| 1839 |
갈색야생마
|
17년 전 | 3222 | |
| 1838 |
갈색야생마
|
17년 전 | 2350 | |
| 1837 |
갈색야생마
|
17년 전 | 2467 | |
| 1836 |
갈색야생마
|
17년 전 | 2530 | |
| 1835 |
갈색야생마
|
17년 전 | 2518 | |
| 1834 |
갈색야생마
|
17년 전 | 2656 | |
| 1833 |
갈색야생마
|
17년 전 | 3180 | |
| 1832 |
갈색야생마
|
17년 전 | 2692 | |
| 1831 |
갈색야생마
|
17년 전 | 1424 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기