2016-09-12 45 views
1

Oracle存儲過程:如何配置遊標的MyBatis映射器作爲輸出參數?

create or replace PROCEDURE "TGT_MPD_PLANOGRAM_SEL_SP" (
    POG_NUM_IN IN VARCHAR2, 
    PLAN_DATA_SEL_CUR OUT SYS_REFCURSOR, 
    SQL_CODE_OUT OUT NUMBER, 
    SQL_ERR_MSG_OUT OUT VARCHAR2) 
AS 
... 

Mapper.xml

<select id="getPlanograms" statementType="CALLABLE" 
     parameterType="com.tgt.snp.pog.vo.PlanogramSearchVO" 
     resultMap="mapResultPlanogram"> 
    { 
     CALL TGT_MPD_PLANOGRAM_SEL_SP(
      #{POG_NUM_IN,javaType=String,jdbcType=VARCHAR,jdbcTypeName=VARCHAR2,mode=IN}, 
      #{PLAN_DATA_SEL_CUR,jdbcType=CURSOR,resultMap=mapResultPlanogram,mode=OUT}, 
      #{SQL_CODE_OUT,javaType=Integer,jdbcType=INTEGER,jdbcTypeName=INTEGER,mode=OUT}, 
      #{SQL_ERR_MSG_OUT,javaType=String,jdbcType=VARCHAR,jdbcTypeName=VARCHAR2,mode=OUT} 
     ) 
    } 
</select> 

VO對象

public class PlanogramSearchVO { 

    public PlanogramSearchVO(){} 
public String getPOG_NUM_IN() { 
     return POG_NUM_IN; 
    } 

    public void setPOG_NUM_IN(String POG_NUM_IN) { 
     this.POG_NUM_IN = POG_NUM_IN; 
    } 

    private String POG_NUM_IN; 

    public ResultSet getPLAN_DATA_SEL_CUR() { 
     return PLAN_DATA_SEL_CUR; 
    } 

    public void setPLAN_DATA_SEL_CUR(ResultSet PLAN_DATA_SEL_CUR) { 
     this.PLAN_DATA_SEL_CUR = PLAN_DATA_SEL_CUR; 
    } 

    private ResultSet PLAN_DATA_SEL_CUR; 

    public Integer getSQL_CODE_OUT() { 
     return SQL_CODE_OUT; 
    } 

    public void setSQL_CODE_OUT(Integer SQL_CODE_OUT) { 
     this.SQL_CODE_OUT = SQL_CODE_OUT; 
    } 

    private Integer SQL_CODE_OUT; 

    public String getSQL_ERR_MSG_OUT() { 
     return SQL_ERR_MSG_OUT; 
    } 

    public void setSQL_ERR_MSG_OUT(String SQL_ERR_MSG_OUT) { 
     this.SQL_ERR_MSG_OUT = SQL_ERR_MSG_OUT; 
    } 

    private String SQL_ERR_MSG_OUT; 
} 

錯誤消息

Caused by: org.springframework.jdbc.UncategorizedSQLException: 
### Error querying database. Cause: java.sql.SQLException: Non supported SQL92 token at position: 1: 
### The error may exist in class path resource [PlanogramMapper.xml] 
### The error may involve com.tgt.snp.pog.mapper.PlanogramMapper.getPlanograms-Inline 
### The error occurred while setting parameters 
### SQL: {   ?,   ?,   ?   = CALL TGT_MPD_PLANOGRAM_SEL_SP(   ?      )   } 
### Cause: java.sql.SQLException: Non supported SQL92 token at position: 1: 
; uncategorized SQLException for SQL []; SQL state [99999]; error code [17034]; Non supported SQL92 token at position: 1: ; nested exception is java.sql.SQLException: Non supported SQL92 token at position: 1: 

請幫忙指出什麼迪我錯了嗎?提前致謝。

回答

1

<select>元素不需要resultMap屬性,因爲它不在這裏使用:調用帶出參數的過程,即使是光標/ ResultSet和不是選擇

您可能需要指定Java類型導致的參數定義設置:

#{PLAN_DATA_SEL_CUR, jdbcType=CURSOR, javaType=java.sql.ResultSet, resultMap=mapResultPlanogram, mode=OUT} 

PlanogramSearchVO類屬性PLAN_DATA_SEL_CUR切不可java.sql.ResultSet而是像List<Planogram>如果結果地圖mapResultPlanogram地圖光標結果爲Planogram對象。

Mybatis正在執行將resultSet/Cursor讀取/映射到對象列表的工作;缺點是隻有當遊標被完全獲取時才返回控件:沒有自定義的結果處理,懶惰/不同的加載,...我有answered another question about this

相關問題