批量插入(Test)
- <insert id="insertData" parameterType="java.util.List" >
- INSERT INTO EMP(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) (
- <foreach collection="list" item="item" index="index" separator="union all">
- select
- #{item.EMPNO,jdbcType=VARCHAR},
- #{item.ENAME,jdbcType=VARCHAR},
- #{item.JOB,jdbcType=VARCHAR},
- #{item.MGR,jdbcType=NUMERIC},
- #{item.MGR,jdbcType=NUMERIC},
- TO_DATE(#{item.HIREDATE,jdbcType=VARCHAR},'yyyy-mm-dd')
- from dual
- </foreach>
- )
- </insert>
=====================================================================declaretype t_array is table of t_target%rowtype;t_data t_array;cursor c isselect null id, owner, object_name, null object_id, null xx, null yyfrom dba_objects;beginopen c;loopfetch c bulk collectinto t_data limit 100;forall i in 1 .. t_data.countinsert into t_target values t_data (i);exit when c%notfound;end loop;close c;commit;end;<insert id="insertByProc" statementType="CALLABLE">
{call insertPro(#{name},#{age},#{sex},#{password},#{num})}
</insert>1 CREATE DEFINER = `root`@`localhost` PROCEDURE `NewProc`(IN `name_in` varchar(255),IN `age_in` int,IN `sex_in` varchar(255),IN `password_in` varchar(255),IN `num_in` int) 2 BEGIN 3 SET @a=0; 4 Label:LOOP 5 SET @a=@a+1; 6 INSERT INTO person ( name, age, sex, password) VALUES (name_in,age_in,sex_in,password_in); 7 IF @a=num_in THEN 8 LEAVE Label; 9 END IF; 10 END LOOP Label; 11 END;
posted on 2014-04-15 21:38 Rabbit 閱讀(1155) 評(píng)論(0) 編輯 收藏