create or replace procedure pro_js9295(MSG Out Varchar2) Is
    ln_months Number; 
Begin
  ln_months := '0';
  For t In (select * from table t Where t.year<='1995')Loop
    While (ln_months < t.months) Loop
      Insert Into js9295(year,month)
      Values (t.year,(13-ln_months));
      ln_months := ln_months+1;
       Commit;
      End Loop;
     End Loop;  
End pro_js9295;
--过程编译没有问题。
目的是想把表中的数据按照月数拆分条数。例如如果表中月数months为10,则拆成
3条。
事实上,我大循环的语句select * from table t Where t.year<='1995' 取到的条数是4条。
如果分别是3,4,5,6个月数。那么结果应该拆成3+4+5+6条。
可处理结果只取到大循环的一条数据。。貌似也是随机取到的。
很纳闷啊。求指点。。

解决方案 »

  1.   

    更改下,插入的value那的month应该是12-ln_months
      

  2.   

    create or replace procedure pro_js9295(MSG Out Varchar2) Is
         ln_months Number; 
     Begin
       ln_months := '0';
       For t In (select * from table t Where t.year<='1995')Loop
         While (ln_months < t.months) Loop
           Insert Into js9295(year,month)
           Values (t.year,(13-ln_months));
           ln_months := ln_months+1;
            Commit;
           End Loop;
           ln_months := '0';
          End Loop;  
     End pro_js9295;