存储过程应用实例及应用语法说明

create or replace procedure P_YQ001_01(YQ00102VALUE in VARCHAR2,
                                       YQ00108VALUE in VARCHAR2,
                                       YQ00201VALUE in VARCHAR2,
                                       YQ00206VALUE out numeric) is
  --YQ00102VALUE 

  --YQ00108VALUE 
  --YQ00201VALUE

  --YQ00206VALUE 返回值


  value1 numeric;--当前顺序号
  value2 numeric;--最大值
  value3 numeric;--最小值
begin
  select yq2.yq00206,yq2.yq00204 ,yq2.yq00205  into value1,value2,value3 from YQ002 yq2 
   where yq2.yq00201 = YQ00201VALUE
     and yq2.yq00202 = YQ00102VALUE
     and yq2.yq00203 = YQ00108VALUE;
 

--当序号大于最大值或小于最小值时,进行重新设置,本例设置为最小值加1,因为最小值为0

--if()....then....elsif ().... then .... else ....end if;是存储过程中条件判断语法
  if(value1>=value2) then    
         value1:=value3+1;    
  elsif(value1<=value3) then   
          value1:=value3+1;
  else  
        value1:=value1+1;   
  end if;
 
  YQ00206VALUE:=value1;
  update YQ002 yq2
     set yq2.yq00206 = YQ00206VALUE
   where yq2.yq00204 > value1
     and yq2.yq00205 < value1
     and yq2.yq00201 = YQ00201VALUE
     and yq2.yq00202 = YQ00102VALUE
     and yq2.yq00203 = YQ00108VALUE;
  commit;
  DBMS_OUTPUT.put_line(YQ00206VALUE);

  --异常处理

  exception

    when no_data_found then           --SELECT未找到记录异常
         DBMS_OUTPUT.put_line('获取银企支付交易序号控制登记薄序号信息报错,请仔细检查。');
    when others then                         --其它异常
         DBMS_OUTPUT.put_line('更新银企支付交易序号控制登记薄序号信息报错,请仔细检查。');
end;

你可能感兴趣的:(存储过程应用实例及应用语法说明)