日期:2014-05-17  浏览次数:21023 次

oracle 循环语句
SQL code

declare tag_hight number;
        hight integer;
        tag_body number;
       bodytype number;
begin
     tag_hight:=1;
     hight:=160;
     
 while(tag_hight<4) loop 
  --exit when tag_hight>3;
  tag_body:=1;
  bodytype:=130;  
  while(tag_gbdy<4)
      loop             
           --exit  when tag_body>3;
            insert into YU values(tag_hight,'XX','YYY',to_char(bodytype)||'/'||to_char(hight)||'b','0');
             bodytype:=bodytype+2;
             tag_body:=tag_body+1;
       end loop  
        tag_hight:=tag_hight+1;
        hight:=hight+5;
        
  end loop;
 end;


提示 tag_hight:=tag_hight+1; 这出错,无效的语句?
第一次写这个,高手指点下

------解决方案--------------------
SQL code

SQL> select * from t;

 ID IDNAME       TYPE
--- ------------ ----

SQL> 
SQL> declare
  2    tag_hight number;
  3    hight integer;
  4    tag_body number;
  5    bodytype number;
  6  begin
  7    tag_hight:=1;
  8    hight:=160;
  9   while(tag_hight<4) loop
 10      tag_body:=1;
 11      bodytype:=130;
 12      while(tag_body<4)
 13      loop
 14        insert into t values(1,'a',1);
 15        bodytype:=bodytype+2;
 16        tag_body:=tag_body+1;
 17      end loop;
 18      tag_hight:=tag_hight+1;
 19      hight:=hight+5;
 20    end loop;
 21   end;
 22  /

PL/SQL procedure successfully completed

SQL> select * from t;

 ID IDNAME       TYPE
--- ------------ ----
  1 a               1
  1 a               1
  1 a               1
  1 a               1
  1 a               1
  1 a               1
  1 a               1
  1 a               1
  1 a               1

9 rows selected

SQL>

------解决方案--------------------
end loop 也不加个';'号