up

解决方案 »

  1.   

    求某个字段的所有数据的积?写个函数,
    create or replace function fun_test return number as 
        p_out number:=1;
        v_temp number;
        cursor c is select * from 表名;
    begin 
        open c ;
        loop
            fetch c into v_temp;
            exit when c%notfound; 
            p_out:=p_out*v_temp;
        end loop;
        close c;
        return p_out;
        exception 
            when others then 
               return -99;
    end
      

  2.   

    ---> 
    cursor c is select nvl(字段,1) from 表名;
      

  3.   

    我還想求字符串相加呢.
    假如有table x有兩個欄位f1,f2,三行數據
    -------
    f1   f2
    -------
    a     1
    a     2
    a     3 
    SELECT F1, COUNT(F2) FROM X GROUP BY F1
    結果為  a,3
    -----------------------------------------
    SELECT F1, SUM(F2) FROM X GROUP BY F1
    結果為 a, 6
    -----------------------------------------
    -----我想得到 a, 123 該怎麼辦????????
    -----------------------------------------  
      

  4.   

    也得写函数。思路:用CURSOR取f2的值,循环处理将他们用||拼接起来