CREATE PROCEDURE cs_mlt_query(dtime date) 
AS
declare @loop_num varchar(1024)  --游标所用的循环变量
um money  number;              --每次记录中的金额
num money number :=0;      --所有记录的金额之和  begin
  for i_cur in (select distinct sccardid from comcardlog)
    loop
      select clmoney into um
       from comcardlog 
       where sccardid =i_cur.sccardid
        and  cltradedt < dtime
     order by cltradedt desc;
     num := num+um;   
    end loop;
end;

解决方案 »

  1.   


    create or replace procedure mlt_query(dtime date)
    as
      loop_num varchar2(1024);
      um       number(18,4);
      num      number(18,4);
      type v_cursor is ref cursor;
    cursor_1 v_cursor;
    begin
      open cursor_1 for  select distinct sccardid from comcardlog;
      loop
        fetch cursor_1 into loop_num;
         exit where cursor_1%notfound;
         
         select clmoney into um from comcardlog where rownum=1 and sccardid =loop_num and trunc(cltradedt) < trunc(dtime) order by cltradedt desc;
         num:=num+um;
      end loop;
      close cursor_1;
      
      dbms_output.put_line(to_char(num));
    end mlt_query;
      

  2.   

    begin 
      mlt_query('2004-11-25 23:00:00');
    end;
    为什么不能执行呀!
    说我参数类型不对!
      

  3.   

    你要写成mlt_query(to_date('2004-11-25 23:00:00','yyyy-mm-dd hh24:mi:ss'));