PL SQL基本迴圈語句

2022-08-22 02:06:10 字數 1219 閱讀 3553

基本迴圈結構包含loopend loop語句之間的語句序列。通過每次迭代,執行語句序列,然後在迴圈頂部繼續控制。

pl/sql程式語言的基本迴圈語法是 -

loop 

sequence of statements;

end loop;

這裡,語句序列(sequence of statements;)可以是單個語句或一組語句。需要乙個exit語句或乙個exit when語句來中斷迴圈。

通過下面乙個簡單的示例來演示loop語句如何使用 -

set serveroutput on size 1000000;

declare

x number := 10;

begin

loop

dbms_output.put_line(x);

x := x + 10;

if x > 50 then

exit;

end if;

end loop;

-- after exit, control resumes here

dbms_output.put_line('after exit x is: ' || x);

end;

/

當上述**在sql提示符下執行時,它會產生以下結果 -

可以使用exit when語句來代替exit語句 -

set serveroutput on size 1000000;

declare

x number := 10;

begin

loop

dbms_output.put_line(x);

x := x + 10;

exit when x > 50;

end loop;

-- after exit, control resumes here

dbms_output.put_line('after exit x is: ' || x);

end;

/

當上述**在sql提示符下執行時,它會產生以下結果 -

PL SQL 迴圈控制語句

判斷語句 if.else declare v age number not null 50 beginif0 v age and v age 18 then dbms output.put line 兒童 elsif 18 v age and v age 30 then dbms output.pu...

PLSQL基本控制語句

根據員工號,查詢員工薪水 declare v empno emp.empno type v sal emp.sal type begin v empno 7369 select sal into v sal from emp where empno v empno dbms output.put l...

怎樣記住PL SQL迴圈語句

iamlaosong文 oracle pl sql的迴圈控制語句有三種,如何記住呢?很簡單,那就是 基本結構loop。end loop,基本結構前加個while,或者基本結構前加個for。基本結構用exit或者exit when退出,其它兩種除此之外,還根據while或者for退出,即 1 基本結構...