我在做报表设计,有种情况就是在一个表格中每个单元格都会绑定一个sql语句,然后我要到数据库中查出这些sql语句的值再回填到对应的单元格中,
如果有100个单元格我就要查询数据库100次,这个过程很慢。我查询些资料知道用存储过程可以实现一批Sql语句的查询,但是这里面涉及到的东西比较多,
比如这100个sql语句作为一个事务来处理,返回结果是否得用到游标。我觉得很复杂的,一直也没搞明白,那位高手帮帮我,指点我写出这个存储过程或者其他的实现方法?我只有16分,全给您了,高手应该不是太在乎这些的吧,以后有机会会加倍补偿的。

解决方案 »

  1.   

    大量的sql如果不通过优化合并,将会成为性能的瓶颈
      

  2.   

    比如,我要到数据库A中查询 select [column1] from [table1] where [condition1];
    select [column2] from [table2] where [condition2];
    select [column3] from [table3] where [condition3];
    select [column4] from [table4] where [condition4];我想一起把查询结果通过某种方式传出来。。怎么实现,最好用存储过程
      

  3.   

    2楼,我现在只想把功能实现了,具体到sql的优化还没想那么多呢
      

  4.   

    select [column1] from [table1] where [condition1]
    union all
    select [column2] from [table2] where [condition2]
    union all
    select [column3] from [table3] where [condition3]
    union all
    select [column4] from [table4] where [condition4]
    如果数据类型不存在兼容性问题,那么上面的语句就可以,问题是,这样的结果有什么意义?
      

  5.   

    我是要每一个结果对应一个报表中的单元格的,而去单元格绑定的sql语句是随时变化的,我要把返回的结果赋值给每个单元格的
      

  6.   

    并不是一个sql语句只返回一个值,有的返回一个,有的返回多个
      

  7.   

    报表 最好用存储过程来执行,返回最终的结果,最后插入到数据库里的表里,然后用程序select 出来
      

  8.   

    估计不好实现,因为你这个sql的个数都是不确定的.用包的重载试试:create or replace package a
    is
    procedure p(p_1 out sys_refcursor);
    procedure p(p_1 out sys_refcursor, p_2 out sys_refcursor);
    procedure p(p_1 out sys_refcursor, p_2 out sys_refcursor, p_3 out sys_refcursor);
    ...
    end a;
      

  9.   

    报表?
      好像做过类似的东西 ,遇到 一样的情况。
      我最后也是用存取过程,在存取过程里用临时表,这样多用户同时查的时候不会串,也避免同一用户开两个同时查询而出错的概率。
      临时表里可以有一列单元格标识,将所有的要取的值转换为字符就不会有数据类型问题了。
      然后像6楼说的Union起来,
      select '1' as cellFlag,[column1] from [table1] where [condition1]
    union all
    select '2' as cellFlag,[column2] from [table2] where [condition2]
    union all
    select '3' as cellFlag,[column3] from [table3] where [condition3]
    union all
    select '4' as cellFlag,[column4] from [table4] where [condition4] 
      出报表的时候根据cellFlag去对应吧!