日期:2014-05-16 浏览次数:20403 次
?
ibatis调用oracle的函数,存储过程的方法 IN 和OUT /游标
2009-05-18 14:17
1对于全部是in 类型的参数过程,采用下面的方法调用(ibatis版本是2.3)
比如过程:
?????????? Procedure Flashback_Op(v_table_owner Varchar2,v_table_name Varchar2,v_FlashbackScn Number,v_xid Varchar2,v_dbid number);
调用方法:
<parameterMap id="tableDml_recycle" class="java.util.Map">
???? <parameter property="owner" jdbcType="VARCHAR"
??????? javaType="java.lang.String" mode="IN " />
??????? <parameter property="name" jdbcType=" VARCHAR "
?????????? javaType="java.lang.String" mode="IN " />
???? <parameter property="scn" jdbcType="NUMBER"
??????????? javaType="java.math.BigDecimal" mode="IN " />
<parameter property="xid" jdbcType=" VARCHAR "
?????????? javaType="java.lang.String" mode="IN " />
??? ? <parameter property="dbId" jdbcType="NUMBER"
??????? javaType="java.math.BigDecimal" mode="IN " />
??? </parameterMap>
???
??? <procedure id="tableDml "?????
?parameterMap=" tableDml_zcRecycle ">??
??????? {call TassetREC.Flashback_Op(?,?,?,?,?)}??
??? </procedure>?
2对于返回类型是游标 (OUT)的函数,采用如下方式调用。
函数:
Function GetFirstPageNumRows(v_where varchar2,v_dbid Number,v_Numrows varchar2,v_queryid varchar2) return sys_refcursor ;
调用方式:
<parameterMap id="searchParam" class="java.util.Map">
??????? <parameter property="result" jdbcType="ORACLECURSOR"
??????? javaType="java.sql.ResultSet" mode="OUT " resultMap="auditselect_resultList" />
???????
??????? <parameter property="ipAddress"
??????????? jdbcType="varchar" javaType="java.lang.String" mode="IN" />
??????? <parameter property="dbId" jdbcType="NUMBER"
??????????? javaType="java.math.BigDecimal" mode="IN"/>
??????? <parameter property="countNumber" jdbcType="NUMBER"
??????????? javaType="java.lang.Integer" mode="IN"/>
??????? <parameter property="clientId" jdbcType="VARCHAR2"
??????????? javaType="java.lang.String" mode="IN"/>
??? </parameterMap>
<function id="firstPage" parameterMap="searchParam">??
??????? {? = call tlgadmin.GetFirstPageNumRows(?,?,?,?)}?? (注意返回值在前面用?代表)
??? </ function >
java代码这么取值:
@SuppressWarnings("unchecked")
??? public List getAuditSelectByPages(Map map) {
??????? getSqlMapClientTemplate().queryForList("firstPage", map);//调用
??????? List arryList = (ArrayList) map.get("result");//取值
??????? return arryList;
??? }
3对于返回值为一般数据类型的函数:
函数:
Function DeleteCommand(v_commandid Number,v_commandsetid Number default 0,v_dbid Number default 0) return Number ;
采用如下方式处理(把返回值当作出参来处理OUT):
<parameterMap id="CommandDeleteById" class="java.util.Map">
??????? <parameter property="result" jdbcType="VARCHAR"
?????????? javaType="java.lang.String" mode="OUT" />
??????? <parameter property="commandId" jdbcType="NUMBER"
??????????? javaType="java.lang.Integer" mode="IN" />
??????? <parameter property="commandsetId" jdbcType="NUMBER"
??????????? javaType="java.lang.Integer" mode="IN" />
??????? <parameter property="dbId" jdbcType="NUMBER"
??????????? javaType="java.math.BigDecimal" mode="IN" />
??? </parameterMap>
<function id="Command_deleteById"
??????? parameterMap="CommandDeleteById">
?????? { ? = call truleadmin.DeleteCommand(?,?,?)}
? </ function>
?