一、Orcal存储过程语法
--定义存储过程开始 create or replace procedure pm_quotaresult_tablename( --定义入参 v_fundcode in varchar2, v_bendyeildid in varchar2, v_busidate in varchar2 ) AS p_achievementnav zt_tablename.achievementnav%type;--定义替换变量 p_countnav zt_tablename.achievementnav%type; BEGIN --定义游标 DECLARE CURSOR p_benchmark IS select p.benchmarkid,p.rundate,p.resultvalue from pm_quotaresult p where p.benchmarkid = v_bendyeildid and rundate >= v_busidate order by rundate; p_benchmarkid varchar2(50);--查询字段定义 p_rundate pm_quotaresult.rundate%type;--用原表的字段类型 p_resultvalue varchar2(50); BEGIN OPEN p_benchmark; LOOP FETCH p_benchmark INTO p_benchmarkid,p_rundate,p_resultvalue; --开始遍历,字段于上面定义字段顺序一致 exit when p_benchmark%notfound; --逻辑判断计算 if p_rundate = v_busidate then p_countnav := 1 * (p_resultvalue+1) - 1; DBMS_OUTPUT.put_line( p_countnav); p_achievementnav := 1; else p_countnav := (1 + p_countnav) * (p_resultvalue+1) - 1; DBMS_OUTPUT.put_line( p_countnav); p_achievementnav := 1 + p_countnav; end if; -- 3.修改tablename表中的数据 update zt_tablename set benchyield = p_resultvalue,achievementnav = p_achievementnav where fundcode = v_fundcode and busidate = p_rundate; END LOOP; CLOSE p_benchmark; END; COMMIT; END pm_quotaresult_tablename;
二、执行存储过程
call pm_quotaresult_tablename('111015','15556','20161118');