Problems encountered when adding and modifying Mybatis to oracle database in batches

Wrote a method for batch addition:

           INSERT INTO CRD_SUBSIDY_AMOUNT (  
              	id,  
              	DELETED,  
              	CREATED_BY,  
              	CREATED_DATE,  
              	ORGANIZATION_ID,  
              	REMARK,  
              	SUBSIDY_GRANT_AMT,  
              	MONTH_OF_YEAR,  
              	SURPLUS_AMT,  
              	USED_AMT,  
              	AMOUNT_ID,  
              	ALLOW_USED_SUBSIDY_AMT,  
              	STAFF_ID,  
              	STAFF_NAME   
              )  
              VALUES  
            <foreach collection='subsidyAmounts' item='item' index='index' separator=','>  
             (  
               #{ item.id }, 
               #{ item.del }, 
               #{ item.createdBy },    
               #{ item.createdDate }, 
               #{ item.organizationId }, 
               #{ item.remark } ,  
               #{ item.subsidyGrantAmt }, 
               #{ item.monthOfYear }, 
               #{ item.surplusAmt }, 
               #{ item.usedAmt }, 
               #{ item.amountId },  
              	#{ item.allowUsedSubsidyAmt },  
              	#{ item.staffId }, 
               #{ item.staffName }   
              	)
						</foreach>

Report an error for no reason during execution

Say that SQL did not end correctly.

Later, I found out that this is SQL for Mysql

So I changed the SQL


INSERT INTO CRD_SUBSIDY_AMOUNT (  
		id,  
		DELETED,  
		CREATED_BY,  
		CREATED_DATE,  
		ORGANIZATION_ID,  
		REMARK,  
		SUBSIDY_GRANT_AMT,  
		MONTH_OF_YEAR,  
		SURPLUS_AMT,  
		USED_AMT,  
		AMOUNT_ID,  
		ALLOW_USED_SUBSIDY_AMT,  
		STAFF_ID,  
		STAFF_NAME   
	)  
SELECT  A.*
FROM(
<foreach collection="list" item="item" index="index" separator="UNION ALL">
 SELECT
			 #{ item.id,jdbcType=VARCHAR } id,  
			 #{ item.del ,jdbcType=NUMBER} DELETED, 
			 #{ item.createdBy,jdbcType=VARCHAR } CREATED_BY,    
			 #{ item.createdDate,jdbcType=TIMESTAMP} CREATED_DATE, 
			 #{ item.organizationId,jdbcType=VARCHAR } ORGANIZATION_ID, 
			 #{ item.remark,jdbcType=VARCHAR } REMARK,  
			 #{ item.subsidyGrantAmt,jdbcType=VARCHAR } SUBSIDY_GRANT_AMT, 
			 #{ item.monthOfYear,jdbcType=VARCHAR } MONTH_OF_YEAR, 
			 #{ item.surplusAmt ,jdbcType=VARCHAR} SURPLUS_AMT, 
			 #{ item.usedAmt,jdbcType=VARCHAR } USED_AMT, 
			 #{ item.amountId ,jdbcType=VARCHAR} AMOUNT_ID,  
			 #{ item.allowUsedSubsidyAmt,jdbcType=VARCHAR } ALLOW_USED_SUBSIDY_AMT,  
			 #{ item.staffId,jdbcType=VARCHAR } STAFF_ID, 
			 #{ item.staffName,jdbcType=VARCHAR } STAFF_NAME  
     FROM dual
   </foreach>
   )A

 

After the execution, an error was reported:

Mapper method 'xxx' has an unsupported return type

This kind of error indicates that the sql statement is executed successfully, but the return type is wrong.

Solution:

Insert, delete, and update operations return an integer of type int by default, and you can change the interface for addition, deletion, and modification to int or void.

The type returned by the select operation can be a custom Map or List

Just change the return value type.

 

After that, I wrote a batch modification:

                 <foreach collection='list' item='item' index='index' open='begin' 
                         close=';end;' separator=';'> 
                         update CRD_SUBSIDY_AMOUNT t 
                         set 
                         t.ALLOW_USED_SUBSIDY_AMT=#{item.allowUsedSubsidyAmt}, 
                         t.LAST_MODIFIED_BY='system', 
                         t.LAST_MODIFIED_DATE=sysdate 
                         where t.STAFF_ID = #{item.staffId} 
                     </foreach> 

 

 

ps: Because it is an Oracle database, the now() function cannot be used for the new and modified time fields , so the sysdate function is written .

Guess you like

Origin blog.csdn.net/admin123404/article/details/107207125