array operations

create or replace procedure SFGL_XF_SFBZ(p_xn     in varchar2,
                                         p_czr    in varchar2,
                                         o_errMsg out varchar2) is
  /**
  * Generate charging standard
  * Function: Generate charging standards by school year. 1. The charging standards for new grades are generated; 2. Grades that have already graduated will not be generated.

  * October 21, 2016
  * p_xn school year
  * p_czr current operator
  * o_errMsg returns error message
  */
  v_xn1 varchar2(10); -- record the first year of the school year eg: 2016 in 2016-2017
  before_Xn varchar2(10); -- record the previous school year
  type t_arr is varray(3) of varchar2(20); -- grade array
  v_nj t_arr;
  v_count number := 0; -- the number of record queries

begin
  v_xn1 := substr(p_xn, 1, 4);  --eg:2017
  before_Xn := (v_xn1-1)||'-'||v_xn1;  --eg:2016-2017
  v_nj := t_arr(null, null,null);
  v_nj(1) := v_xn1-2;  --eg:2015
  v_nj(2) := v_xn1-1;  --eg:2016
  v_nj(3) := v_xn1;  --eg:2017
  
  --Determine whether the school year data for the first two grades have been generated
  for x in 1..v_nj.count-1 loop
      v_count :=0;
      select count(1) into v_count from sfgl_xf t where t.xn=p_xn and t.nj = v_nj(x);
      if v_count = 0 then
         insert into sfgl_xf(xfid,yxdm,zydm,fy,modified_time,modified_by,create_time,create_by,nj,zsfy,xn,ybfy)
         select Xl_Sfgl_Xf.NEXTVAL,t.yxdm,t.zydm,t.fy,sysdate,p_czr,sysdate,p_czr,t.nj,t.zsfy,p_xn,t.ybfy from sfgl_xf t where t.xn=before_Xn and t.nj = v_nj(x);
      end if;    
      
  end loop;
  
  --Generate the data of the latest grade, the latest grade of the previous school year shall prevail
  --eg: The 2016 grade data of 2016-2017 refer to the 2015 grade data of 2015-2016
  v_count :=0;
   select count(1) into v_count from sfgl_xf t where t.xn=p_xn and t.nj = v_nj(3);
    if v_count = 0 then
       insert into sfgl_xf(xfid,yxdm,zydm,fy,modified_time,modified_by,create_time,create_by,nj,zsfy,xn,ybfy)
       select Xl_Sfgl_Xf.NEXTVAL,t.yxdm,t.zydm,t.fy,sysdate,p_czr,sysdate,p_czr,v_nj(3),t.zsfy,p_xn,t.ybfy from sfgl_xf t where t.xn=before_Xn and t.nj = v_nj(2);
    end if;  
    
         
exception
  when others then
    o_errMsg := 'An internal error occurred while running the program, please contact the administrator. ';
    raise;
end SFGL_XF_SFBZ;

 

type t_arr is varray(3) of varchar2(20); -- grade array

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326564024&siteId=291194637