問題:用mybaits 批量插入數據到Oracle 數據庫的時候,java
報錯:ORA-00933: SQL 命令未正確結束 / ORA-00933: SQL command not properly ended ;意思就是 語法錯誤 mysql
緣由:sql
oracle 批量插入與mysql 的批量插入的方式是不一樣的,數據庫
insert into tablename()values(),(),(); ---這個是mysql 的批量插入形式oracle
insert all into tablename() values() into tablename() values() -------這個是Oracle批量插入形式 spa
下面是 Mybaits:oracle數據庫批量插入數據的樣式:code
//方式1: <insert id="insertclobtest2" parameterType="com.inspur.tax.sjaqgl.sjflfjgl.data.ClobEntity"> INSERT ALL <foreach collection="list" item="item" index="index"> INTO ainsertclob (id, blobtest) VALUES (#{item.id}, #{item.blobtest}) </foreach> select 1 from dual </insert> //方式2: <insert id="insertclobtest3" parameterType="com.inspur.tax.sjaqgl.sjflfjgl.data.ClobEntity"> INSERT INTO ainsertclob (id, blobtest) <foreach collection="list" item="item" index="index" separator="union all"> SELECT #{item.id} ,#{item.blobtest} from dual </foreach> </insert> // 方式3: <insert id="addBatch" parameterType="java.util.List"> BEGIN <foreach collection="list" item="item" index="index" separator=""> insert into blacklist (id, userid, deviceid, createdate, updatedate, "LEVEL") VALUES ( USER_INFO_SEQ.NEXTVAL,#{item.userId,jdbcType=INTEGER},#{item.deviceId,jdbcType=VARCHAR}, #{item.createDate,jdbcType=DATE},sysdate, #{item.level,jdbcType=INTEGER} ); </foreach> COMMIT; END; </insert>
下面是Mybaits: mysql 數據庫批量插入數據的例子:blog
<insert id="insertclobtest1" parameterType="com.inspur.tax.sjaqgl.sjflfjgl.data.ClobEntity"> INSERT INTO ainsertclob (id, blobtest) VALUES <foreach collection="list" item="item" separator=","> (#{item.id}, #{item.blobtest}) </foreach> </insert>
Mybatis,oracle,ORA-00933: SQL 命令未正確結束it
緣由是:批量插入時,若是沒有主鍵,必定要顯式指定useGeneratedKeys爲false,不然會報: SQL 命令未正確結束io
<insert id="insert_" useGeneratedKeys="false"> </insert>