要实现的功能是:比如数据:. .  .   . 5 
. .  .   . 4 
. .  .   . 0 
. .  .   . 0 
. .  .   . 4 
. .  .   . 3
. .  .   . 0
. .  .   . 0
. .  .   . 3 我想写个sql 或过程,函数什么的东西。
实现:按顺序将大于零的在一起的数据累加,并存成一条数据(到另外一张表)。实现后: . .  .   . 5+4=9
        . .  .   . 4+3=7
        . .  .   . 3=3

解决方案 »

  1.   

    没有关键字段的话可以用rownum来做关联,不过你得思路很有问题
      

  2.   

    给你写个存储过程实现吧:SQL> select t from test;
     
             T
    ----------
             5
             4
             0
             0
             4
             3
             0
             0
             3
             0
     
    10 rows selected
    create or replace procedure pro_t
    as
    s number:=0;
    temp number:=0;
    begin
    for cu in (select t from test) loop
    if cu.t>0  and temp=0 then s:=s+1;
    temp:=1;
    elsif cu.t=0 then temp:=0;
    end if;
    end loop;
    dbms_output.put_line(s);
    end;SQL> exec pro_t;
     
    3
    PL/SQL procedure successfully completed