Example:-
BEGIN
FOR EMPREC IN (SELECT * FROM EMPLOYEES) LOOP
DBMS_OUTPUT.PUT_LINE(EMPREC.LAST_NAME||' GETS '||EMPREC.SALARY);
END LOOP;
END;
Output
SQL> set serveroutput on
SQL> /
OConnell GETS 2600
Grant GETS 2600
Whalen GETS 4400
Hartstein GETS 15000
Fay GETS 8000
Mavris GETS 6500
Baer GETS 10000
Higgins GETS 12000
Gietz GETS 8300
King GETS 24000
Kochhar GETS 17000
De Haan GETS 17000
Hunold GETS 9000
Ernst GETS 6000
Austin GETS 4800
Pataballa GETS 4800
Lorentz GETS 4200
Greenberg GETS 12000
Faviet GETS 9000
Chen GETS 8200
Sciarra GETS 7700
Urman GETS 7800
Popp GETS 6900
Raphaely GETS 11000
Khoo GETS 3100
Baida GETS 2900
Tobias GETS 2800
Himuro GETS 2600
Colmenares GETS 2500
Weiss GETS 8000
Fripp GETS 8200
Example 2:-
DECLARE
CURSOR EMPCUR IS SELECT * FROM EMPLOYEES;
BEGIN
FOR EMPREC IN EMPCUR LOOP
DBMS_OUTPUT.PUT_LINE(EMPREC.LAST_NAME||' GETS '||EMPREC.SALARY);
EXIT WHEN EMPCUR%ROWCOUNT>=10;
END LOOP;
END;
0 comments:
Post a Comment