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 dual



    insert 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、创建序列

删除序列语法: 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 List queryPageBadUserInfo(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文件:


    SELECT tt.*	FROM
    (
    	
        SELECT t.*, ROWNUM rown, COUNT (*) OVER () total FROM
        (
            select  from T_BAD_USER_W
            
                
                    and city = #{city}
                
                
                    and county = #{county}
                
                
                    and loadtime >= to_date(#{startTime} , 'yyyy-mm-dd hh34:mi:ss')
                
                
                    and loadtime  to_date(#{endTime} , 'yyyy-mm-dd hh34:mi:ss')
                
            
        )t
    )tt
    where tt.rown > #{start} and tt.rown  #{end}

后端海量数据导出,批量查询

service业务实现:

public List queryPageBadUserInfo(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文件编写



    SELECT tt.*	FROM
    (
        SELECT t.*, ROWNUM rown FROM
        (
            select  from T_BAD_USER_W
            
                
                    and city = #{city}
                
                
                    and county = #{county}
                
                
                    and loadtime >= to_date(#{startTime} , 'yyyy-mm-dd hh34:mi:ss')
                
                
                    and loadtime  to_date(#{endTime} , 'yyyy-mm-dd hh34:mi:ss')
                
            
        )t where ROWNUM  #{end}
    )tt
    where tt.rown > #{start}
本文转载于:https://www.yisu.com/zixun/722591.html 如有侵犯,请联系zhengruancom@outlook.com删除。
免责声明:正软商城发布此文仅为传递信息,不代表正软商城认同其观点或证实其描述。