첫 번째로, 바보 같은 질문 인 경우 사과해야하지만 PL/SQL을 처음 사용합니다.키 - 값을 PL/SQL 프로 시저에 전달하는 방법은 무엇입니까?
java 및 PL/SQL을 사용하여 Oracle 데이터베이스와 상호 작용해야하는 프로젝트 작업 중입니다. 데이터베이스에 전달하고자하는 키 - 값의 결정할 수없는 목록이 있습니다. 초기 연구에서 oracle.sql.STRUCT 및 oracle.sql.ARRAY를 가리키는 것으로 보입니다.
데이터베이스 측에 기존 객체/테이블 유형이 필요하기 때문에 STRUCT 및 ARRAY 객체를 선호하지 않습니다.
편집 : 내 자바 코드
java.sql.Connection connection = myGetConnection();
// create variables for the oracle.sql.ARRAY
ArrayDescriptor arraydesc = ArrayDescriptor.createDescriptor("TEXT_TABLE", connection);
Object[] arrayObject = new Object[2];
//create STRUCT objects
StructDescriptor descriptor = StructDescriptor.createDescriptor("MYITEM", connection);
// Loop through the map and put objects in the arrayObject
for(int i = 0; i < myMap.size(); i++){
String key = "key"+1;
String value = "value"+2;
Object[] obj = {key,value};
STRUCT structObj = new STRUCT(descriptor, connection, obj);
// put the struct object in the array object
arrayObject[i] = structObj;
}
// create the oracle.sql.ARRAY
ARRAY array = new ARRAY(arraydesc, connection, arrayObject);
//..
oracleCallableStatement = connection.prepareCall("{call myPackage.myProcedure(?)}");
oracleCallableStatement.setArray(1, array);
oracleCallableStatement.execute();
oracleCallableStatement.close();
내가 excplictly 내 오라클 데이터베이스 차종의 형식을 선언해야한다는 사실을에 내 PL에
/SQL
CREATE OR REPLACE TYPE myItem AS object (c1 VARCHAR2(10), c2 VARCHAR2(30));
CREATE OR REPLACE TYPE text_table AS TABLE OF myItem ;
나는 일을하는 더 쉬운 방법이 있어야한다고 생각합니다. 이것들은 매우 원시적 인 객체입니다.
이것이 올바른 방법인가요? 이것이 내 유일한 옵션입니까?