这个存储过程怎么写?(oracle)刚接触oracle哈table A
id   num
01    1
02    2
03    3
需更新A表,得到如下结果(也就是说02=01+02 计算完成后 03=02+03)id   num
01    1
02    3
03    6

解决方案 »

  1.   


    select id,sum(num)over(order by id) num from temp
      

  2.   

    不好意思,结果是对的。我怎么更新呢?select 只是得到结果?
      

  3.   


    for c in select id,sum(num)over(order by id) num from a
    loop
      update a set a.num = c.num where id = a.id;
      commit;
    end loop;
      

  4.   

    willflyz
    想要一个完整的存储过程
    由于刚接触oracle。
    谢谢!
      

  5.   

    我也好久没用oracle了,
    create or replace procedure yourprocedureName
    is
    begin
    for c in select id,sum(num)over(order by id) num from a
    loop
      update a set a.num = c.num where id = a.id;
    end loop;
    commit;
    end;
      

  6.   

    创建存储过程的语句如下:
    CREATE[OR REPLACE] PROCEDURE<过程名>
    <参数1>,「方式l]<数据类型1>,
    <参数2>,[ 方式2]<数据类型2>,
    ……)
    IS|AS is_或as完全等价
    BEGIN
    PL/SQL过程体
    END<过程名>
    找本书看一下就好了.
      

  7.   

    CREATE[OR REPLACE] PROCEDURE<过程名> 
    <参数1>,「方式l]<数据类型1>, 
    <参数2>,[ 方式2]<数据类型2>, 
    ……) 
    IS|AS is_或as完全等价 
    BEGIN 
    PL/SQL过程体 
    END<过程名>