日期:2014-05-17  浏览次数:20813 次

oracle存储过程
通过oracle存储过程,从同一个数据表一个时间差的数据的差值。如,表s_pm_cpu有time,value,equip三个字段,这个时间段的减去上一个时间段的value值,oracle新手,请大家帮忙写一个,谢谢,并讲一下如何在数据库中自动运行,谢谢了

------解决方案--------------------
SQL code

CREATE OR REPLACE PROCEDURE prc_pm_cpu(in_portid integer,
                                       in_stime  date,
                                       in_etime  date) is
  v_value number;
  v_mincpuused number;
  v_maxcpuused number;
begin
  begin
    select t.cpuused
      into v_mincpuused
      from s_pm_cpu t
     where t.portid = in_portid and t.starttime=in_stime;
     
    select t.cpuused 
      into v_maxcpuused
      from s_pm_cpu t
     where t.portid = in_portid and t.starttime=in_etime;
     
 v_value:=v_maxcpuused-v_mincpuused;
 
  end;
  commit;
end prc_pm_cpu;