CoderZone.org

Category: >> Oracle PL/SQL >> WHILE LOOP example Bookmark and Share

<< lastnext >>

Snippet Name: WHILE LOOP example

Description: Basic WHILE loop skeleton code.

Comment: (none)

Author: CoderZone
Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: February 27th, 2009

DECLARE
    salary          emp.sal%TYPE;
    mgr_num         emp.mgr%TYPE;
    last_name       emp.ename%TYPE;
    starting_empno  CONSTANT NUMBER(4) := 7902;
BEGIN
    SELECT sal, mgr INTO salary, mgr_num FROM emp
        WHERE empno = starting_empno;
    WHILE salary < 4000 LOOP
        SELECT sal, mgr, ename INTO salary, mgr_num, last_name
            FROM emp
            WHERE empno = mgr_num;
    END LOOP;
 
    INSERT INTO temp VALUES (NULL, salary, last_name);
    COMMIT;
END;
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 6