oracle中的条件控制语句
流程控制 :if(条件语句1)then
{语句1}
elsif {条件语句2}then
{语句2}
else {语句3}
end if
如declare
ni varchar(20);--定义变量
begin
select xb into ni from a where xm='大哥'; --只接受单个值
if ni is not null then --判断语句,ni是否为空
dbms_output.put_line(ni);
else
dbms_output.put_line('不存在');
end if; --结束if
end;--结束执行
流程控制————>case when 分支
case 变量/表达式
流程语句1
when 值
else
流程语句2
end case
declare
ni varchar(20);--定义变量
begin
select xm into ni from a where xm='大哥';--只接受单个值
case ni
when '大哥' then--判断 ni='大哥',只接受 ‘真或假’
dbms_output.put_line(ni);
else
dbms_output.put_line('不存在');
end case; --结束case
end;--结束执行
无条件循环
loop end loop, 一直循环,可以用exit,goto 中断
while循环
while 条件判断 loop 循环操作 end loop
for 循环
for 变量名 in 循环开始的数字,循环结束的数字 loop 循环操作 end loop;
所有的循环都差不多如下所示
declare
wo integer;--定义变量
ni varchar(20);--定义变量
begin
for wo in 1..3 loop --把1-3的值赋给wo,开始循环
select xm into ni from a where xm='大哥';
dbms_output.put_line(ni);
end loop; --结束case
end;--结束执行