Mybatis inserts data into Oracle and MySQL databases in batches. you must first understand the syntax supported by this database for batch inserts. The syntax for batch insert in each database is different. I will introduce two types.
MySQL: 1. insert into TABLE_NAME (ID, NAME) VALUES (1, 'Zhang San'), (2, 'Li si ')
2. insert into TABLE_NAME (ID, NAME) VALUES (1, 'Zhang San'); insert into TABLE_NAME (ID, NAME) VALUES (2, 'Li si ')
Oracle: 1. insert into TABLE_NAME (ID, NAME) (SELECT 1, 'Zhang San' from dual) union all (SELECT 2, 'Li Si' from dual)
2. insert into TABLE_NAME (ID, NAME) VALUES (1, 'Zhang San'); insert into TABLE_NAME (ID, NAME) VALUES (2, 'Li si ')
All four SQL statements are supported by the database. The second method is not recommended because it is far worse than the first one regardless of efficiency or readability.
Of course, more importantly, Mybatis does not support the second method, because one transaction of mybatis only supports one SQL statement.
Therefore, the first method in Mybatis can only be used. the code is as follows:
MySQL
INSERT INTO TABLE_NAME(ID,NAME) VALUES(#{itm.id},#{itm.name})
ORACLE:
INSERT INTO TABLE_NAME(ID,NAME) (SELECT #{itm.id},#{itm.name} FROM DUAL)
Note that the label must be , Cannot beOrOtherwise, an error is reported ..Don't ask your brother why he reported an error. he doesn't know either... (I am too lazy to check the information. if you are interested, you can check the information)