13. Oracle 中逻辑控制语句
If elsif else end if
set serverout on;
declare per_dep_count number;
begin
select count(*) into per_dep_count from emp;
if per_dep_count>0 then
dbms_output.put_line('Big Than 0');
elsif per_dep_count>5 then --elsif not elseif!!!!
dbms_output.put_line('Big Than 5');
else
dbms_output.put_line('En?');
end if;
end;
14.Case when 的使用的两种方式
(1)
declare per_dep_count number;
begin
select count(*) into per_dep_count from emp;
case per_dep_count
when 1 then
dbms_output.put_line('1');
when 2 then
dbms_output.put_line('2');
else
dbms_output.put_line('else');
end case;
end;
(2)
declare per_dep_count number;
begin
select count(*) into per_dep_count from emp;
case
when per_dep_count=1 then
dbms_output.put_line('1');
when per_dep_count=2 then
dbms_output.put_line('2');
else
dbms_output.put_line('else');
end case;
end;
14. While 的使用
declare v_id number:=0;
begin
while v_id<5 loop
v_id:=v_id+1;
dbms_output.put_line(v_id);
end loop;
end;
15.For的使用
declare v_id number:=0;
begin
for v_id in 1..5 loop
dbms_output.put_line(v_id);
end loop;
end;