分支语句

if then

elsif then

else

end if

举例:

set serveroutput on
declare
num number;
begin
  num:=3;
  if num = 5
    then
      dbms_output.put_line('这个数字是5');
    elsif num >7
    then 
      dbms_output.put_line('这个数字大于7');
    else
      dbms_output.put_line('其他数字');
  end if;
end;

循环语句

loop

exit when

end loop

例子:

set serveroutput on
declare
num number;
begin
  num := 1;
  select * into stemp from student s where s.sno='109'
  loop
    exit when num > 10;
    dbms_output.put_line(num);
    num := num + 1;
  end loop;
end;

while

loop

end loop

set serveroutput on
declare
num number;
begin
  num := 1;
  select * into stemp from student s where s.sno='109'
while num < 10 
    loop
      dbms_output.put_line(num);
      num := num + 1;
    end loop;
end;

for li in()

loop

end loop

例子:

set serveroutput on
declare
num number;
begin
  num := 1;
  select * into stemp from student s where s.sno='109'
for ii in (select sname from student)
    loop
      dbms_output.put_line(ii.sname);
    end loop;
end;

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-15
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2021-09-11
相关资源
相似解决方案