ibatis对存储过程的调用

简介:

from:‍http://blog.csdn.net/hfhwfw/archive/2010/05/05/5559409.aspx

 

 

‍IBatis映射文件:

<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" > 
<sqlMap namespace="BUSSINESS_B_T_PRODUCT" > 
     
<parameterMap id="hasAuthParam" class="java.util.HashMap" > 
    <parameter property="p_productCode" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/> 
    <parameter property="p_customerId" jdbcType="NUMBER" javaType="java.lang.Long" mode="IN"/> 
    <parameter property="p_callType" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/> 
    <parameter property="p_total" jdbcType="NUMBER" javaType="java.lang.Long" mode="IN"/> 
    <parameter property="result" jdbcType="INTEGER" javaType="java.lang.Integer" mode="INOUT"/> 
</parameterMap> 

<procedure id="hasAuth" parameterMap="hasAuthParam" > 
<!--[CDATA[   
      {call BUSINESSES_HAS_AUTH(?,?,?,?,?)}   
]]--> 
</procedure> 
     
</sqlMap> 
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="BUSSINESS_B_T_PRODUCT" >

<parameterMap id="hasAuthParam" class="java.util.HashMap" >
    <parameter property="p_productCode" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
    <parameter property="p_customerId" jdbcType="NUMBER" javaType="java.lang.Long" mode="IN"/>
    <parameter property="p_callType" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
    <parameter property="p_total" jdbcType="NUMBER" javaType="java.lang.Long" mode="IN"/>
    <parameter property="result" jdbcType="INTEGER" javaType="java.lang.Integer" mode="INOUT"/>
</parameterMap>

<procedure id="hasAuth" parameterMap="hasAuthParam" >
<!--[CDATA[
      {call BUSINESSES_HAS_AUTH(?,?,?,?,?)}
]]-->
</procedure>

</sqlMap>

DAO层代码:

view plaincopy to clipboardprint?
public Integer hasAuth(String productCode, Long customerId,String callType,Long total){   
        Map<String,Object> map = new HashMap<String,Object>();   
        map.put("p_productCode", productCode);   
        map.put("p_customerId", customerId);   
        map.put("p_callType", callType);   
        map.put("p_total", total);   
        map.put("result", -1);   
        queryData("BUSSINESS_B_T_PRODUCT.hasAuth", map);   
        Integer result = (Integer)map.get("result");   
        System.out.println(result);   
        return Integer.valueOf(result);   
    } 
public Integer hasAuth(String productCode, Long customerId,String callType,Long total){
   Map<String,Object> map = new HashMap<String,Object>();
   map.put("p_productCode", productCode);
   map.put("p_customerId", customerId);
   map.put("p_callType", callType);
   map.put("p_total", total);
   map.put("result", -1);
   queryData("BUSSINESS_B_T_PRODUCT.hasAuth", map);
   Integer result = (Integer)map.get("result");
   System.out.println(result);
        return Integer.valueOf(result);
}

 

存储过程:

view plaincopy to clipboardprint?
CREATE OR REPLACE PROCEDURE GBOSS.BUSINESSES_HAS_AUTH   
(p_productCode IN VARCHAR2, p_customerId IN number, p_callType IN VARCHAR2,p_total in number,result out integer)   
is   
v_count integer;   
v_stateCount integer;   
v_seviceTypeState varchar(1);   
v_outstanding C_T_CUSTOMER.OUTSTANDING%type;      
v_billingModel C_T_CUSTOMER_PRODUCT.CP_BILLING_MODEL%type; v_unitPrice C_T_CUSTOMER_PRODUCT.UNIT_PRICE%type;   
v_cpId C_T_CUSTOMER_PRODUCT.CP_ID%type;             
v_currConsu C_T_CUSTOMER_PRODUCT.Curr_Consu%type;     
v_q C_T_BLXS_PRICING.q%type;       
v_p2 C_T_BLXS_PRICING.P2%type;      
BEGIN   
result:=0;                      
select count(1) into v_count from C_T_CUSTOMER_PRODUCT cp,B_T_PRODUCT p,C_T_SERVICE_TYPE t   
where p.PRODUCT_ID=cp.PRODUCT_ID and cp.CP_ID=t.CP_ID and cp.OPER_STATE='1' and t.ST_SERVICE_TYPE=p_callType     
and p.PRODUCT_CODE=p_productCode and cp.CUSTOMER_ID=p_customerId;   
     
if v_count=0 then result:=41 ;         
elsif v_count>1 then result:=42 ;     
elsif v_count=1 then    

     select t.ST_SERVICE_TYPE_STATE,c.OUTSTANDING,cp.CP_BILLING_MODEL,cp.UNIT_PRICE,cp.cp_id,cp.curr_consu     
     into v_seviceTypeState,v_outstanding,v_billingModel,v_unitPrice,v_cpId,v_currConsu    
     from C_T_CUSTOMER_PRODUCT cp,B_T_PRODUCT p,C_T_SERVICE_TYPE t,C_T_CUSTOMER c   
     where p.PRODUCT_ID=cp.PRODUCT_ID and cp.CP_ID=t.CP_ID and cp.OPER_STATE='1' and t.ST_SERVICE_TYPE=p_callType and p.PRODUCT_CODE=p_productCode and cp.CUSTOMER_ID=p_customerId   
            and c.CUSTOMER_ID=cp.CUSTOMER_ID;   
               
     if v_seviceTypeState='2' then        
         select count(1) into v_stateCount from C_T_CUSTOMER_PRODUCT cp,B_T_PRODUCT p,C_T_SERVICE_TYPE t   
         where p.PRODUCT_ID=cp.PRODUCT_ID and cp.CP_ID=t.CP_ID and cp.OPER_STATE='1' and t.ST_SERVICE_TYPE=p_callType and p.PRODUCT_CODE=p_productCode   
                and cp.CUSTOMER_ID=p_customerId and t.ST_SERVICE_TYPE_STATE ='2' and cp.CP_INF_BONUS>cp.CP_INF_USE;   
         if v_stateCount>0 then result:=3;       
         else result:=43;                        
         end if;   

     elsif v_seviceTypeState='3' then     
         select count(1) into v_stateCount from C_T_CUSTOMER_PRODUCT cp,B_T_PRODUCT p,C_T_SERVICE_TYPE t   
         where p.PRODUCT_ID=cp.PRODUCT_ID and cp.CP_ID=t.CP_ID and cp.OPER_STATE='1' and t.ST_SERVICE_TYPE=p_callType and p.PRODUCT_CODE=p_productCode   
                and cp.CUSTOMER_ID=p_customerId and t.ST_SERVICE_TYPE_STATE ='3' and cp.CP_DATA_BONUS>cp.CP_DATA_USE;   
         if v_stateCount>0 then result:=4;      
         else result:=44;                       
         end if;   
     end if;   

end if;   
exception   
when others then   
result := 48;   
END;

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hfhwfw/archive/2010/05/05/5559409.aspx

相关文章
|
存储 SQL
ibatis调用sqlserver存储过程
获取分页的每页结果存储过程 CREATE PROCEDURE [dbo].[mst_sp_pageshowex4]  --输入参数     @qCols varchar(8000),             --     @qTables   varchar(8000),          --      @qWhere   varchar(8000),          --     @oK
1797 0
|
3月前
|
存储 SQL 关系型数据库
MySQL 进阶使用【函数、索引、视图、存储过程、存储函数、触发器】(2)
MySQL 进阶使用【函数、索引、视图、存储过程、存储函数、触发器】
|
22天前
|
存储 关系型数据库 MySQL
Mysql表结构同步存储过程(适用于模版表)
Mysql表结构同步存储过程(适用于模版表)
31 0
|
27天前
|
存储 SQL 关系型数据库
MySQL 创建存储过程注意项
MySQL 创建存储过程注意项
28 0
|
2月前
|
存储 SQL 关系型数据库
(十四)全解MySQL之各方位事无巨细的剖析存储过程与触发器!
前面的MySQL系列章节中,一直在反复讲述MySQL一些偏理论、底层的知识,很少有涉及到实用技巧的分享,而在本章中则会阐述MySQL一个特别实用的功能,即MySQL的存储过程和触发器。
|
2月前
|
存储 SQL 数据库
MySQL设计规约问题之为什么要避免使用存储过程、触发器和函数
MySQL设计规约问题之为什么要避免使用存储过程、触发器和函数
|
3月前
|
存储 SQL 关系型数据库
MySQL数据库进阶第四篇(视图/存储过程/触发器)
MySQL数据库进阶第四篇(视图/存储过程/触发器)
|
3月前
|
存储 SQL 关系型数据库
MySQL存储过程和存储函数的使用
MySQL的存储过程和存储函数在功能和用法上有明显的区别。存储过程是一组为了完成特定功能的SQL语句集,经编译后存储在数据库中,通过指定名称和参数(如果有)来调用执行,可以返回多个值或结果集,但不直接返回值。而存储函数则是一个有返回值的特殊存储过程,它返回一个值或表对象,可以直接嵌入SQL语句中使用,如SELECT语句中。两者都是为了提高SQL代码的重用性和性能,但使用场景和方式有所不同。
186 4
下一篇
DDNS