4

我正在尝试执行一个具有记录表输入输出参数的 oracle 存储过程:

TYPE RECORD_TYP IS RECORD (
    CAT_CD                 VARCHAR2(4),
    MOD_ID       NUMBER(6)
);

我发现这个例子谈论List<String>List<Integer>:http: //viralpatel.net/blogs/java-passing-array-to-oracle-stored-procedure/

但是呢List<MyRecordDTO>

编辑:我在这里找到了一个答案,海报使用了 oracle.sql.STRUCT 类型。 http://betteratoracle.com/posts/32-passing-arrays-of-record-types-between-oracle-and-java

使用这个例子,我发现了异常java.sql.SQLException: Internal Error: Inconsistent catalog view。谷歌搜索这个异常,我打电话给 DBA 授予我访问“ RECORD_TYP

4

1 回答 1

1

我知道这是一个非常古老的问题。但我希望这会有所帮助。在这里,我传递了一个自定义类型数组,并期望得到一个自定义类型数组。

        myJavaRequest req = new myJavaRequest();
        req.setEmpId("940006614");
        myJavaReqArray[0] = req;
        List<myJavaResp> myJavaRespLst = new ArrayList<myJavaResp>();

        try {

            //fetch connection (this should be a OracleConnection class).
            OracleConnection oraConn = (OracleConnection) getConnectionFromDB();

            //Set the mappings -- what is the SQL Object type to Java class mappings when it comes to response.
            Map map = oraConn.getTypeMap();
            map.put("MYSCHEMA.SQLRESPDTO", Class.forName("com.myhome.myJavaResp")); 

            //Create the Array descriptor for the input array
            ArrayDescriptor inputArrayDescr = ArrayDescriptor.createDescriptor("MYSCHEMA.MYREQDTOLIST", oraConn);
            ARRAY inputArray = new ARRAY(inputArrayDescr, oraConn, spgPrefReqArray); //This is an Oracle ARRAY

            //Prepare the Stored procedure call
            OracleCallableStatement stmt  = (OracleCallableStatement)oraConn.prepareCall("{ ? = call MYSCHEMA.PKG.SOME_SP(?) }");
            stmt.registerOutParameter(1, OracleTypes.ARRAY, "MYSCHEMA.SQLRESPDTOLIST");
            stmt.setArray(2, inputArray);

            //Lets execute
            stmt.execute();

            //Fetch the Array of Objects that will have the set of expecting response java objects.
            ARRAY outArray = ((OracleCallableStatement)stmt).getARRAY(1);
            Object[] objects = (Object[])outArray.getArray(map);

            if(null != objects && objects.length > 0){
                for(int iIndex=0; iIndex<objects.length; iIndex++){
                    myJavaRespLst.add((myJavaResp)objects[iIndex]);
                }
            }
        }
于 2014-07-04T15:50:35.360 回答