In Oracle stored procedures, the while loop is used to enter the loop when the conditions are met. If the conditions are not met, the loop is jumped out. The syntax is "WHILE conditional LOOP loop body END LOOP;"; the general expression of the while statement is: "while(expression){loop body}".
The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.
While is a basic loop mode. When the condition is met, it enters the loop. After entering the loop, when the condition is not met, it exits the loop.
The general expression of while statement is: while (expression) {loop body}.
WHILE syntax in oracle:
WHILE 条件 LOOP ... END LOOP ;
For example:
set serverout on declare --定义初始值 v_num number:=# begin --编写循环结构和定义循环条件 while v_num<10 loop dbms_output.put_line('第'||v_num||'次输出'); --改变循环条件 v_num:=v_num+1; end loop; end;
The example is as follows:
set serveroutput on declare num int; total int; begin num:=0; total:=0; while num<5 loop num:=num+1; total:=total+num; end loop; dbms_output.put_line('前5个自然数的和是'||total); end;
Recommended tutorial: "Oracle Video Tutorial"
The above is the detailed content of How to use while loop in oracle stored procedure. For more information, please follow other related articles on the PHP Chinese website!