09.01.2015 Views

PL/SQL User's Guide and Reference

PL/SQL User's Guide and Reference

PL/SQL User's Guide and Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Underst<strong>and</strong>ing the Main Features of <strong>PL</strong>/<strong>SQL</strong><br />

the sequence of statements is executed, then control resumes at the top of the loop.<br />

If the condition is false or null, the loop is bypassed <strong>and</strong> control passes to the next<br />

statement.<br />

In the following example, you find the first employee who has a salary over $2500<br />

<strong>and</strong> is higher in the chain of comm<strong>and</strong> than employee 7499:<br />

-- available online in file ’examp3’<br />

DECLARE<br />

salary emp.sal%TYPE := 0;<br />

mgr_num emp.mgr%TYPE;<br />

last_name emp.ename%TYPE;<br />

starting_empno emp.empno%TYPE := 7499;<br />

BEGIN<br />

SELECT mgr INTO mgr_num FROM emp<br />

WHERE empno = starting_empno;<br />

WHILE salary 25000; -- exit loop if condition is true<br />

END LOOP;<br />

-- control resumes here<br />

Sequential Control<br />

The GOTO statement lets you branch to a label unconditionally. The label, an<br />

undeclared identifier enclosed by double angle brackets, must precede an<br />

Overview of <strong>PL</strong>/<strong>SQL</strong> 1-11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!