其实PL/SQL中的循环和分支结构的代码实现逻辑与其他的程序设计语言是差不多的,学会了其中的一个就能够很容易上手另外一个
PL/SQL有四个组成部分,declare、begin、exception、end;(注意有分号)
然后比较简单的一个实例,1-100素数判断,并输出所有的素数
declare
ret number:=1;
i number :=1;
flag number:=1;
begin
dbms_output.put_line('1');
for ret in 2..100 loop
flag:=1;
for i in 2..10 loop
if( ret mod i=0)
then flag:=flag+1;
end if;
end loop;
if(flag=2)
then
dbms_output.put_line(ret);
end if;
end loop;
end;
/