2015-04-30 67 views
0

我有一個需要調用Oracle數據庫包功能的Grails應用程序。Oracle類型RECORD映射到哪種Java類型?

函數的返回值是RECORD Oracle數據類型。

映射到什麼Java Oracle數據類型RECORD

我發現this page,但是,我要麼是盲人,要麼是沒有我需要的信息。

示例代碼:

封裝類型聲明

TYPE subjectDuration IS RECORD (
    min_duration PLS_INTEGER, 
    max_duration PLS_INTEGER 
); 

功能

FUNCTION getSubjectDuration(
    subject_code IN PACKGE.SUBJ_CODE%type, 
    course_number IN PACKGE.CRSE_NUMB%type, 
    term_code IN PACKGE.EFF_TERM%type 
) 
RETURN subjectDuration 
IS 
    record_rowid ROWID; 
    subject_duration subjectDuration; 
BEGIN 
    ... 
    /*function code */ 

    RETURN(subject_duration); 
END; 

Grails的代碼調用上述功能

String packageCheck = "BEGIN packge.getSubjectDuration(:subjectCode, :courseNumber, :termCode); END; " 

sql.call(packageCheck, [subjectCode: subjectCode, courseNumber: courseNumber, termCode: termCode], 
    // OracleTypes.OTHER is the wrong type. I need the correct type for RECORD, which doesn't exist in OracleTypes. 
    Sql.resultSet(OracleTypes.OTHER)) { cursorResults ->   
    if (cursorResults.next()) { 
     def result = cursorResults.getAt(0) 
     log.debug(result) 
    } 
} 

回答

1

我的解決辦法如下:凡在sql.call被指定爲Sql.out()輸出並指定OracleType

import oracle.jdbc.driver.OracleTypes 
... 
try { 
    String packageCheck = "BEGIN csu.swrtcbs.getSubjectDuration(?, ?, ?, ?, ?); END; " 

    sql.call(packageCheck, [subjectCode, courseNumber, termCode, Sql.out(OracleTypes.NUMBER), Sql.out(OracleTypes.NUMBER)]) { minDur, maxDur -> 

     //log.debug("From Banner: Min duration: ${minDur}, Max duration: ${maxDur}") 
     minDuration = (minDur == null) ? 1 : ((java.math.BigDecimal) minDur).toString() 
     maxDuration = (maxDur == null) ? null : ((java.math.BigDecimal) maxDur).toString() 
    } 

    // Do something with the output: minDuration and maxDuration 

} catch (Exception e) { 
    log.error("Something failed.", e) 
} 

相關問題