1、单条数据insert
insert into userinfo (USERID, USERNAME, AGE) values(1001,'小明',20);SELECT userinfo_userid_seq.nextval as userid from dual insert into EPG_ALARM_INFO (USERID, USERNAME, AGE) values (#{userid}, #{username}, #{age})insert into EPG_ALARM_INFO (USERID, USERNAME, AGE, TIME) values (#{userid}, #{username}, #{age}, sysdate)
2、批量数据批量insert
insert all into 的方式返回值由最后的select 决定:
INSERT ALL INTO userinfo (USERID, USERNAME, AGE) values(1001,'小明',20) INTO userinfo (USERID, USERNAME, AGE) values(1002,'小红',18) INTO userinfo (USERID, USERNAME, AGE) values(1003,'张三',23) select 3 from dual; begin insert into userinfo (USERID, USERNAME, AGE) values(1001,'小明',20); insert into userinfo (USERID, USERNAME, AGE) values(1001,'小红',18); insert into userinfo (USERID, USERNAME, AGE) values(1001,'张三',23); end; insert into userinfo (USERID, USERNAME, AGE) select 1001, '小明', 20 from dual union all select 1002, '小红', 18 from dual union all select 1003, '张三', 23 from dual
INSERT ALL INTO userinfo (USERID, USERNAME, AGE) VALUES (#{item.userid}, #{item.username}, #{item.age}) select list.size from dualinsert into EPG_ALARM_INFO (USERID, USERNAME, AGE) select #{item.userid}, #{item.username}, #{item.age} from dual insert into EPG_ALARM_INFO (USERID, USERNAME, AGE) SELECT userinfo_userid_seq.nextval, m.* FROM ( select #{item.username}, #{item.age} from dual ) m
3、创建序列
- minvalue n (/nominvalue):最小值为n
- maxvalue n (/nomaxvalue):最大值为n
- start with n:从n开始计数
- increment by n:每次增加n
- cache n (/nocache):缓存n个sequence值 / 不缓存,如果缓存,则会有跳号的危险
- noorder (/order):不保证序列号按顺序生成请求
- cycle n (/nocycle):如果到达最大值n后,再次从start with n开始
- currval:序列的当前值,新序列必须使用一次nextval 才能获取到值,否则会报错
- nextval:表示序列的下一个值。新序列首次使用时获取的是该序列的初始值,从第二次使用时开始按照设置的步进递增
删除序列语法: drop sequence seq_表名
create sequence SEQ_USERINFO minvalue 1 maxvalue 9999999999 start with 1 increment by 1 nocache; drop sequence SEQ_USERINFO
4、oracle分页查询
前端与后端交互,分页查询
service业务实现:
public ListqueryPageBadUserInfo(TbadUserQuery queryModel) { log.info("分页查询请求参数,{}", JSON.toJSONString(queryModel)); int pageNum = queryModel.getPageNum(); // 开始页 int pageSize = queryModel.getPageSize(); // 每页数量 queryModel.setStart((pageNum - 1) * pageSize); // 开始行数 (+1后) queryModel.setEnd(pageNum * pageSize); // 结束行数 List beans = badUserWDao.queryPageBadUserInfo(queryModel); log.info("最终查询数量:", beans.size()); return beans; }
mapper.xml文件:
后端海量数据导出,批量查询
service业务实现:
public ListqueryPageBadUserInfo(TbadUserQuery queryModel) { log.info("分页查询请求参数,{}", JSON.toJSONString(queryModel)); List result = new ArrayList<>(); int pageNum = queryModel.getPageNum(); // 开始页 int pageSize = queryModel.getPageSize(); // 每页数量(可以每页设置为200/500/1000),每次查询的条数 boolean searchAll = true; while (searchAll){ queryModel.setStart((pageNum - 1) * pageSize); // 开始行数 (+1后) queryModel.setEnd(pageNum * pageSize); // 结束行数 List beans = badUserWDao.queryPageBadUserInfo(queryModel); if (null == beans || beans.size() < pageSize) { searchAll = false; } if (CollectionUtils.isNotEmpty(beans)) { result.addAll(beans); } pageNum++; } log.info("最终查询数量:", result.size()); return result; }
mapper.xml文件编写
到此这篇关于基于Java 利用Mybatis实现oracle批量插入及分页查询的文章就介绍到这了,更多相关Mybatis实现oracle批量插入 内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!