[/code] 觉得应该好好总结一下,ORACLE之PL/SQL学习
begin
if ... then
...
elsif ...then
...
end if;
end;
实例:
[code="sql"]DECLARE
a number;
b varchar2(10);
begin
a:=2;
if a=1 then
b:='a';
elsif a=2 then
b:='b';
else
b:='c';
end if;
DBMS_OUTPUT.PUT_LINE('b is'||b);
end;
/
有关case whencase
when.. then...
when.. then...
end case
实例
DECLARE
a number;
b varchar2(10);
begin
a:=2;
case
when a=1 then b:='a';
when a=2 then b:='b';
when a=3 then b:='c';
else
b:='others';
end case;
DBMS_OUTPUT.PUT_LINE('b is'||b);
end;
/
循环语句
LOOP
...
END LOOP
WHILE expression LOOP
...
END LOOP
FOR counter in[REVERSE] start_value..end_value LOOP
...
END LOOP;
实例(用第一种方式)
declare
x number;
begin
x:=0;
loop
x:=x+1;
if x>=3 then
exit;
end if;
dbms_output.put_line('内:x='||x);
end loop;
dbms_output.put_line('外:x='||x);
end;
/
用exit when方式declare
x number;
begin
x:=0;
loop
x:=x+1;
exit when x>=3;
dbms_output.put_line('内:x='||x);
end loop;
dbms_output.put_line('外:x='||x);
end;
/
用第三种方式,注意这是reverse的俄,如果是1 to 5,就不加reversebegin
for i in reverse 1..5 loop
dbms_output.put_line('i='||i);
end loop;
dbms_output.put_line('end of for loop');
end;
/