Live ORACLE

if you are Oracle Developer ,than this Blog most likely will make you happy.

About my Blog

This Blog particularized for Oracle Developers ... you will see interesting Codes for SQL , PL/SQL as well as new ideas for Developer Suite and Client Tools that will help you in your professional life ... and I hope I reach for your satisfaction.

About Me

I'm Hany Freedom , 25 years old , I live in EL-Minia City in Egypt , I'm Moderator at ArabOUG.org the best Arabic Forum for ORACLE on the Net. if you interested to know more about me .... just Click Here.

Using WHILE-LOOP for Control

DROP TABLE temp CASCADE CONSTRAINTS PURGE;

CREATE TABLE
temp (
tempid NUMBER(6),
tempsal NUMBER(8,2),
tempname VARCHAR2(25));


DECLARE

sal employees.salary%TYPE := 0;

mgr_id employees.manager_id%TYPE;

lname employees.last_name%TYPE;

starting_empid employees.employee_id%TYPE := 120;

BEGIN

SELECT manager_id

INTO mgr_id

FROM employees

WHERE employee_id = starting_empid;



WHILE sal <= 15000 LOOP -- loop until sal > 15000

SELECT salary,

manager_id,

last_name

INTO sal,mgr_id,lname

FROM employees

WHERE employee_id = mgr_id;

END LOOP;



INSERT INTO TEMP

VALUES (NULL,

sal,

lname); -- insert NULL for tempid



COMMIT;

EXCEPTION

WHEN no_data_found THEN

INSERT INTO TEMP

VALUES (NULL,

NULL,

'Not found'); -- insert NULLs



COMMIT;

END;

/



Share/Save/Bookmark

0 comments:

Post a Comment



Newer Posts Older Posts Home Page
 
http://www.dpriver.com/images/sqlpp-banner-2.png

Thanks for reading my Blog ... you Visitor Number :-