zoukankan      html  css  js  c++  java
  • oracle 分页查询数据统计报表

    为防止一次性读取数据过多而内存不足,因此后台每次取出100数据统计,经过多次取;

    从而完成统计!

    例子如下:service方法

    public class QueryClientStatisticsService
    {
        protected ClientStatisticsDao clientStatisticsDao = new ClientStatisticsDaoImp();
       
        public void initConfig(ClientStatisticsDo clientStatisticsDo)
        {
           
            try
            {
                //总记录数
                int AllCouts = clientStatisticsDao.queryClientStatisticsCounts(clientStatisticsDo);
                //每次获取100条数据
                int perCounts = 100;
                //需要取nums次
                int nums = (AllCouts % perCounts) == 0 ? (AllCouts / perCounts)
                        : (AllCouts / perCounts) + 1;
                //记录开始位置
                int start ;
                //记录结束位置
                int end ;
                //分次数取数据
               
                String[] statact;
                String[] founctions;
                //存放nums查询累加的客户端功能点
                Map<String, Integer> map = new HashMap<String, Integer>();
                for (int i = 1; i <= nums; i++)
                {
                    start = (i - 1) * perCounts + 1;
                    end = i * perCounts;
                    clientStatisticsDao.queryClientStatistics(clientStatisticsDo,
                            start,
                            end);
                    //每次取数据时,list存放客户端功能点编号和次数
                    List<String> list = clientStatisticsDo.getList();
                    for (int j = 0; j < list.size(); j++)
                    {
                        //遍历每条记录
                        statact = list.get(j).split(";");
                        for (int k = 0; k < statact.length; k++)
                        {
                            founctions = statact[k].split(":");
                            //对map初始化
                            if (null == map.get(founctions[0]))
                            {
                                map.put(founctions[0], 0);
                            }
                            map.put(founctions[0], map.get(founctions[0])
                                    + Integer.parseInt(founctions[1]));
                        }
                    }
                }
               
                //将map的内容封装到域对象中
                this.transform(clientStatisticsDo, map);
               
            }
            catch (BMSException e)
            {
                DebugLogFactory.error(this.getClass(), "other error:", e);
                throw new GeneralBMEException(String.valueOf(e.getExceptionCode()));
            }
           
        }

    说明:统计的字段样式:0000:5;0001:23;

    2.分页sql语句(需要排序,建立索引):

     SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT * FROM ECONF_CLIENT_STATACT t where substr(t.datetime,1,10) between :beginTime AND :endTime order by t.datetime ) A WHERE ROWNUM <=:end ) WHERE RN >=:start

  • 相关阅读:
    【Shell】Shell介绍及常用shell脚本
    【Redis】Redis底层数据结构原理--简单动态字符串 链表 字典 跳跃表 整数集合 压缩列表等
    检查Mysql主从状态
    三种方式获取随机字符串或数字
    Intellij 编译时报 未结束的字符串字面值
    IDEA 远程调试
    kafka操作命令
    maven idea设置查找依赖优先从指定的本地仓库获取
    详解布隆过滤器的原理、使用场景和注意事项
    IDEA查找接口实现类及快速实现接口
  • 原文地址:https://www.cnblogs.com/qqzy168/p/2674802.html
Copyright © 2011-2022 走看看