SQL分支語句與循環語句


分支語句

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;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM