我有一个调用Oracle数据库包函数所需的Grails应用程序。
该函数的返回值是RECORD
Oracle数据类型。
RECORD
映射到的Java Oracle数据类型是什么?
我找到了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)
}
}
答案 0 :(得分:1)
我的解决方案如下:
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)
}
输出在sql.call
中指定为Sql.out()
并指定OracleType。
答案 1 :(得分:0)
我认为this blog post可能正是您所寻找的。 p>