我写了一个ORACLE的存储过程
里面定义了一个Code变量`
问一下如何判断这个变量里面的最大值  IF Code THEN   ---这里怎么写呢
        INSERT INTO T_TEMP_ReportTempData
        (COLUMN1,COLUMN2,COLUMN3,COLUMN4,COLUMN5,COLUMN6,COLUMN7,COLUMN8,COLUMN9,COLUMN10,VALUEDATA)
  VALUES('合计','总',kindid,kindname,totalmoney,totalWater,strcostYear,strcostMonth,'','','');
       END IF;
   
我的想法是当循环到code 里面最大值的时候`开始插入数据```

解决方案 »

  1.   

    你可以定义一个中间变量,如currentMax=0;
    循环code,如果code>currentMax
    currentMax=code;kindid,kindname,totalmoney,totalWater,strcostYear,strcostMonth赋上相应的值
    一直到最后,循环结束
    插入数据
      

  2.   

    各位大侠,能不能把具体的code贴出来,研究下
      

  3.   

    大至写了一下...
    Create Or Replace Procedure test
    As  
      currentMax     Number:=0;  
      Code           Number:=0;
      CURSOR get_attr_ IS
      SELECT *
      FROM Your_Tab;---循环数据表
      
      CURSOR get_maxt IS
      SELECT Count(*)
      FROM Your_Tab;
      
    begin
       Open get_maxt;
       Fetch get_maxt Into currentMax;---循环数据表的最大记录
       Close get_maxt;
       FOR rec_ IN get_attr_ Loop
           
           BEGIN
            IF Code=currentMax THEN  ---这里怎么写呢 
             INSERT INTO T_TEMP_ReportTempData 
             (COLUMN1,COLUMN2,COLUMN3,COLUMN4,COLUMN5,COLUMN6,COLUMN7,COLUMN8,COLUMN9,COLUMN10,VALUEDATA) 
             VALUES('合计','总',kindid,kindname,totalmoney,totalWater,strcostYear,strcostMonth,'','',''); 
            END IF; 
           END;
           Code:=Code+1;
       END LOOP;  
    End test;
      

  4.   

    你的code 是数组变量还是 自定义变量 还是number变量