First check and then insert instead stored procedures, java parameters into the reference section, mybatisxml [I]

 

First check and then insert the stored procedure changed

create or replace procedure PRO_REVENUE_SI(l_p_cd             in Varchar2,
                                        l_c_cd             in Varchar2,
                                        l_prod_type        in Varchar2,
                                        l_identity_type    in Varchar2,
                                        l_industry_type_id in Varchar2,

                                        l_p_id            in Varchar2,
                                        l_c_id            These  Varchar2 , 
                                        L_rijn_nam      these  Varchar2 , 
                                        L_indstry_kod    these  Varchar2 , 
                                        L_indstry_nam    these  Varchar2 , 
                                        L_pr_indstry_id these  Varchar2 , 
                                        L_indstry_gred   these  Varchar2 , 
                                        Return_val Out Varchar2 
                                        ) 

 the 
  / *
  DECLARE
    l_p_cd Varchar2 (1000): = 8.35 million; 
    l_c_cd Varchar2 (1000): = 8,350,102; 
    l_prod_type Varchar2 (1000): = 10; 
    l_identity_type Varchar2 (1000): = 2; 
    l_industry_type_id Varchar2 (1000): = 2; 

    l_p_id Varchar2 (1000) : =. 1; 
    l_c_id Varchar2 (1000): =. 1; 
    l_region_name Varchar2 (1000): =. 1; 
    l_industry_code Varchar2 (1000): =. 1; 
    l_industry_name Varchar2 (1000): =. 1; 
    l_par_industry_id Varchar2 (1000): =. 1; 
    l_industry_grade VARCHAR2 (1000): =. 1; 
  * / 
  - definition of variables reception parameters, in order to modify the parameters 
  ll_identity_type     VARCHAR2 ( 1000 ):= L_identity_type; 
  ll_industry_type_id VARCHAR2 ( 1000 ): = l_industry_type_id; 

  - function return value 
  - the return_val VARCHAR2 (8000): = 'Start'; 
  - generic cursor 
  CV a SYS_REFCURSOR;
   - creating a query result recording portion for enclosing 
  the TYPE revenue_type the IS the RECORD ( 
    R1 REVENUE_STATISTICS_RES.Audit_Cust_Num % the TYPE, 
    R2 REVENUE_STATISTICS_RES.AUDIT_CUST_PARTY_NUM % the TYPE, 

    T1 REVENUE_STATISTICS_RES.TY_1 % the TYPE, 
    T2 REVENUE_STATISTICS_RES.TY_1 % the TYPE, 
    T3 REVENUE_STATISTICS_RES.TY_1%TYPE,
    t4  REVENUE_STATISTICS_RES.TY_1%TYPE,
    t5  REVENUE_STATISTICS_RES.TY_1%TYPE,
    t6  REVENUE_STATISTICS_RES.TY_1%TYPE,
    t7  REVENUE_STATISTICS_RES.TY_1%TYPE,
    t8  REVENUE_STATISTICS_RES.TY_1%TYPE,
    t9  REVENUE_STATISTICS_RES.TY_1%TYPE,
    t10 REVENUE_STATISTICS_RES.TY_1%TYPE,
    t11 REVENUE_STATISTICS_RES.TY_1%TYPE,
    t12 REVENUE_STATISTICS_RES.TY_1%TYPE,

    y1  REVENUE_STATISTICS_RES.TY_1%TYPE,
    y2  REVENUE_STATISTICS_RES.TY_1%TYPE,
    y3  REVENUE_STATISTICS_RES.TY_1%TYPE,
    y4  REVENUE_STATISTICS_RES.TY_1%TYPE,
    y5  REVENUE_STATISTICS_RES.TY_1%TYPE,
    y6  REVENUE_STATISTICS_RES.TY_1%TYPE,
    y7  REVENUE_STATISTICS_RES.TY_1%TYPE,
    y8  REVENUE_STATISTICS_RES.TY_1%TYPE,
    y9  REVENUE_STATISTICS_RES.TY_1%TYPE,
    y10 REVENUE_STATISTICS_RES.TY_1%TYPE,
    y11 REVENUE_STATISTICS_RES.TY_1%TYPE,
    REVENUE_STATISTICS_RES.TY_1 Y12 % the TYPE);
   - declare variables recording type 
  revenue_rec revenue_type;
   - final query SQL 
  S_all VARCHAR2 ( 3000 ): =  '' ; 

  - substantially the SQL 
  S1 VARCHAR2 ( 1000 ): =  ' the SELECT / * the PARALLEL + (12 is) * / 
                 COUNT (e.CUST_ID) AUDIT_CUST_NUM, COUNT (the DISTINCT (m.PARTY_ID)) AUDIT_CUST_PARTY_NUM, 
  the SUM (TY_1) TY1, the SUM (TY_2) TY2, the SUM (TY_3) TY3, the SUM (TY_4) TY4, SUM (TY_5) TY5, SUM ( TY_6) TY6, SUM (TY_7) TY7, SUM (TY_8) TY8, SUM (TY_9) TY9, SUM (TY_10) TY10, SUM (TY_11) TY11, SUM (TY_12) TY12, 
  the SUM (LY_1) LY1, the SUM (ly_2) LY2, the SUM (LY_3) LY3, the SUM (LY_4) LY4, the SUM (LY_5) LY5 , the SUM (LY_6) LY6, the SUM (LY_7) LY7, the SUM (LY_8) LY8, the SUM (LY_9) LY9, the SUM (LY_10) LY10, the SUM (LY_11) LY11, the SUM (LY_12) of LY12 
             the FROM EDA_CUST_INC E, m CUST_CP_MERGE 
             the WHERE
                   e.CUST_ID = m.CUST_ID
               AND e.STD_LATN_CD = m.STD_LATN_CD
               and m.PARTY_ID IS NOT NULL
               AND UPPER(m.PARTY_ID) != NULL
               AND   e.STD_PRVNCE_CD = ' || l_p_cd ||
                       ' AND e.STD_LATN_CD = ' || l_c_cd;

  --产品类型
  s_prod_type varchar2(1000) := ' AND   e.PROD_TYPE =' || l_prod_type;

  --身份证类型
  s_identity varchar2(1000) := ' AND EXISTS (SELECT 1
                        FROM PARTY P
                       WHERE m.PARTY_ID = p.PARTY_ID
                           AND p.IDENTITY_TYPE = ' ||
                               l_identity_type || ')';

  --行业类型
  s_industry varchar2(1000) := ' and exists (select 1
                          from party_org po
                         m.party_id = po.party_id WHERE 
                             and po.INDUSTRY_TYPE_ID = '  || 
                               l_industry_type_id ||  ' ) ' ; 

the BEGIN 
  - treatment products Parameter Type 
  / * 
  the IF l_prod_type null IS 
  THEN 
    s_prod_type: =' the AND IS e.PROD_TYPE null '; 
  the END the IF; 
  * / 
  - process type parameter identification 
  the IF l_identity_type =  ' -1 '  THEN 
    s_identity: =  ' the AND Not EXISTS (the SELECT. 1 
                            the FROM P the PARTY 
                           the WHERE m.PARTY_ID = p.PARTY_ID) ' ; 
  ELSIF l_identity_type =  ' -2 '  THEN 
    s_identity: =  ' the AND EXISTS (the SELECT. 1 
                          the FROM P the PARTY
                         WHERE m.PARTY_ID = p.PARTY_ID
                             AND p.IDENTITY_TYPE is null)';
  END IF;

  --处理行业类型参数
  IF l_identity_type = '-1' THEN
    s_industry := ' and not exists (select 1
                            from party_org po
                           where m.party_id = po.party_id)';
  ELSIF l_identity_type = '-2' THEN
    s_industry := ' and exists (select 1
                          from party_org po
                         m.party_id = po.party_id WHERE 
                             and po.INDUSTRY_TYPE_ID IS null) ' ;
   the END  the IF ; 

  - splicing the last query SQL 
  S_all: = S1 || s_prod_type || s_identity || s_industry; 
  the DBMS_OUTPUT.PUT_LINE (S_all); 
  the return_val: =  ' query SQL: '  || S_all;
   - open the generic cursor 
  the oPEN CV the fOR S_all;
   - will be assigned to a variable cursor 
  FETCH CV
     INTO revenue_rec;
   -Cursor off 
  the CLOSE CV; 

  - to a local variable assigned for use (apply to the use of the parameters passed conversion) is inserted behind 
  the IF l_identity_type ! =  ' . 1 '  and l_identity_type =!  ' 2 '  THEN 
    ll_identity_type: =  null ;
   the END  the IF ; 

  the IF l_industry_type_id =  ' -1 '  orl_industry_type_id =  ' -2 '  THEN 
    ll_industry_type_id: =  null ;
   the END  the IF ; 

  - insertion 
  INSERT  INTO REVENUE_STATISTICS_RES 
    (ID, 
     AUDIT_CUST_NUM, 
     AUDIT_CUST_PARTY_NUM, 
     TY_1, 
     TY_2, 
     TY_3, 
     TY_4, 
     TY_5, 
     TY_6, 
     TY_7, 
     TY_8, 
     TY_9, 
     TY_10, 
     TY_11 , 
     TY_12, 
     LY_1, 
     ly_2, 
     LY_3, 
     LY_4, 
     LY_5, 
     LY_6, 
     LY_7, 
     LY_8, 
     LY_9, 
     LY_10, 
     LY_11, 
     LY_12, 

     PROVINCE_REGION_ID, 
     CITY_REGION_ID, 
     REGION_NAME,

     IDENTITY_TYPE,
     PROD_TYPE,

     INDUSTRY_TYPE_ID,
     INDUSTRY_TYPE_CODE,
     INDUSTRY_TYPE_NAME,
     PAR_INDUSTRY_TYPE_ID,
     INDUSTRY_TYPE_GRADE,

     IN_DATE)
    select SEQ_REVENUE_STATISTICS_RES.NEXTVAL, f.*
      from (SELECT revenue_rec.r1,
                   revenue_rec.r2,

                   revenue_rec.t1,
                   revenue_rec.t2,
                   revenue_rec.t3,
                   revenue_rec.t4,
                   revenue_rec.t5,
                   revenue_rec.t6,
                   revenue_rec.t7,
                   revenue_rec.t8,
                   revenue_rec.t9,
                   revenue_rec.t10,
                   revenue_rec.t11,
                   revenue_rec.t12,

                   revenue_rec.y1,
                   revenue_rec.y2,
                   revenue_rec.y3,
                   revenue_rec.y4,
                   revenue_rec.y5,
                   revenue_rec.y6,
                   revenue_rec.y7,
                   revenue_rec.y8,
                   revenue_rec.y9,
                   revenue_rec.y10,
                   revenue_rec.y11,
                   revenue_rec.y12,

                   l_p_id,
                   l_c_id,
                   l_region_name,

                   ll_identity_type,
                   l_prod_type,

                   ll_industry_type_id,
                   l_industry_code,
                   l_industry_name,
                   l_par_industry_id,
                   l_industry_grade,

                   sysdate
              from dual) f;
  COMMIT;
  return_val := '插入完成';
  --return return_val;

/*The EXCEPTION 
  the WHEN the OTHERS THEN 
    the return_val: = the return_val || 'exception code:' || SQLCODE || 'abnormality information:' || SQLERRM variables,;
    --return return_val;
    DBMS_OUTPUT.PUT_LINE(return_val);
    - throws an exception 
    RAISE; 
    * / 
END ;

 

java code section:

mybatis of xml:

<select id="callRevenue" parameterMap="fMap" statementType="CALLABLE" >
          CALL PRO_REVENUE_SI(?,?,?,?,?,?,?,?,?,?,?,?,?)       
</select>
      
 <parameterMap type="java.util.Map" id="fMap">
         <parameter property="l_p_cd" mode="IN" jdbcType="VARCHAR"/>
         <parameter property="l_c_cd" mode="IN" jdbcType="VARCHAR"/>
         <parameter property="l_prod_type" mode="IN" jdbcType="VARCHAR"/>
         <parameter property="l_identity_type" mode="IN" jdbcType="VARCHAR"/>
         <parameter property="l_industry_type_id" mode="IN" jdbcType="VARCHAR"/>
         <parameter property="l_p_id" mode="IN" jdbcType="VARCHAR"/>
         <parameter property="l_c_id" mode="IN" jdbcType="VARCHAR"/>
         <parameter property="l_region_name" mode="IN" jdbcType="VARCHAR"/>
         <parameter property="l_industry_code" mode="IN" jdbcType="VARCHAR"/>
         <parameter property="l_industry_name" mode="IN" jdbcType="VARCHAR"/>
         <parameter property="l_par_industry_id" mode="IN" jdbcType="VARCHAR"/>
         <parameter property="l_industry_grade" mode="IN" jdbcType="VARCHAR"/>
         <parameter property="return_val" mode="OUT" jdbcType="VARCHAR"/>
</parameterMap>

 

java code:

       Map map = new HashMap();
            map.put("l_p_cd", ep.get("STD_PRVNCE_CD"));
            map.put("l_c_cd", ep.get("STD_LATN_CD"));
            map.put("l_prod_type", ep.get("PROD_TYPE"));
            map.put("l_identity_type", ep.get("IDENTITY_TYPE"));
            map.put("l_industry_type_id", ep.get("INDUSTRY_TYPE_ID"));
            map.put("l_p_id", ep.get("PROVINCE_REGION_ID"));
            map.put("l_c_id", ep.get("CITY_REGION_ID"));
            map.put("l_region_name", ep.get("REGION_NAME"));
            map.put("l_industry_code", ep.get("INDUSTRY_TYPE_CODE"));
            map.put("l_industry_name", ep.get("INDUSTRY_TYPE_NAME"));
            map.put("l_par_industry_id", ep.get("PAR_INDUSTRY_TYPE_ID"));
            map.put("l_industry_grade", ep.get("INDUSTRY_TYPE_GRADE"));
            map.put("return_val", "");
            logger.info("入参:{}",map);
            
            String selectOne = sqlSession.selectOne("ds2", "revenueStatistics.callRevenue",map);
            logger.info("出参:{}",map.get("return_val"));

 

Guess you like

Origin www.cnblogs.com/libin6505/p/11779006.html