[/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;
/
本文详细介绍了 ORACLE 数据库中 PL/SQL 的基本控制结构,包括条件判断(IF...THEN)、CASE 语句及循环(LOOP、WHILE、FOR)。通过具体实例展示了如何使用这些结构来实现逻辑控制。
1053

被折叠的 条评论
为什么被折叠?



