如题。
我要实现的功能的代码(SQL Server 2000下)是:
declare @total NUMERIC(16,9)
set @total=(select sum(DBLUNVOUCHERDEBIT) from accountdaily)select sum(DBLUNVOUCHERDEBIT)/@total from accountdaily group by LNGACCOUNTID在Oracle中该如何实现?

解决方案 »

  1.   

    declare  
      total number(16,9);
    begin
      select  sum(DBLUNVOUCHERDEBIT) into total from accountdaily;
       --余者同此处理。
    end;
      

  2.   

    oracle9以上的版本
    create or replace procedure ss(curs out REFCURSOR) is
    total NUMERIC(16,9);
    begin
      total=(select sum(DBLUNVOUCHERDEBIT) from accountdaily);
      open curs for select sum(DBLUNVOUCHERDEBIT)/@total from accountdaily group by LNGACCOUNTID;
    end ss;都可以用
    create or replace package package_cur is
      type ref_cursor is ref cursor;
    end package_cur;create or replace procedure proselect(srefcursor out package_cur.ref_cursor) is
    total NUMERIC(16,9);
    begin
      total=(select sum(DBLUNVOUCHERDEBIT) from accountdaily);
      open curs for select sum(DBLUNVOUCHERDEBIT)/@total from accountdaily group by LNGACCOUNTID;
    end proselect;
      

  3.   

    select sum(DBLUNVOUCHERDEBIT)/(select sum(DBLUNVOUCHERDEBIT) from test) as col1 
    from test group by LNGACCOUNTID;
      

  4.   

    snowy_howe(天下有雪) :你试过在Oracle 8.17版本下可以吗?为什么我用PL/SQL Developer执行时会报错:不是Group By表达式?dobetterthatnthink(如果你没有那么多的选择):你的方法我早已试过,报语法错误!不知您测试过没有?
      

  5.   

    我的只是一个意思而已,至于结果对不对,应该自己测试了。而且这个是在pl/sq
      

  6.   

    pl/sql deveoper上写的test script
      

  7.   

    SQL> select * from test;LNGACCOUNT DBLUNVOUCHERDEBIT
    ---------- -----------------
    a                       1000
    a                       2000
    a                       3000
    b                       4000
    b                       2500
    b                       1500已选择6行。SQL> SELECT a.lngaccountid, a.part / b.total AS per
      2    FROM (SELECT   lngaccountid, SUM (dblunvoucherdebit) AS part
      3              FROM TEST
      4          GROUP BY lngaccountid) a,
      5         (SELECT SUM (dblunvoucherdebit) total
      6            FROM TEST) b
      7  /LNGACCOUNT        PER
    ---------- ----------
    a          .428571429
    b          .571428571SQL> 我尝试过我的那个语句确实在817环境不能运行,大概是因为817中子查询不能作为
    公式项出现?
    上面这个保证是在标准817环境下测试的,可用。
      

  8.   

    declare total NUMERIC(16,9)
    select sum(DBLUNVOUCHERDEBIT) into total from accountdaily
    select sum(DBLUNVOUCHERDEBIT)/total from accountdaily group by LNGACCOUNTID