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

用pl/Sql写一个从1加到10的例子,为啥通不过呢?
declare  
    i     integer;
    s     integer;
begin
    i:=1;
    s:=0;
    loop  
        s:=s+1;
        exit       when     i <11;
    end   loop
    dbms_output.put_line(s);
end;

------解决方案--------------------
declare
i integer;
s integer;
begin
i:=1;
s:=0;
loop
s:=s+1;
exit when i <11;
end loop;
dbms_output.put_line(s);
end;

end loop 少了;
楼主粗心啦!
------解决方案--------------------
是的,楼主太粗心了。
------解决方案--------------------
是啊 少 分号
------解决方案--------------------
不单单是少;号!而且退出条件应该是i> =11;
------解决方案--------------------
还有你怎么不让i=i+1;
------解决方案--------------------
declare
ctrl integer:=0;
begin
dbms_output.enable;
loop
dbms_output.put(ctrl || ' ');
ctrl:=ctrl+1;
exit when ctrl=10;
end loop;
dbms_output.put_line ( ' ');
end;
/

------解决方案--------------------
顶!
------解决方案--------------------
declare
i integer;
s integer;
begin
i:=1;
s:=0;
loop
s:=s+1;
i:=i+1;
exit when i <11;
end loop;
dbms_output.put_line(s);
end;