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.

Retrieving Query Results With BULK COLLECT

DECLARE
TYPE numtab IS TABLE OF employees.employee_id%TYPE;
TYPE nametab IS TABLE OF employees.last_name%TYPE;
enums NUMTAB; -- No need to initialize the collections.
names NAMETAB; -- Values will be filled in by the SELECT INTO.
PROCEDURE Print_results
IS
BEGIN
IF enums.COUNT = 0 THEN
dbms_output.Put_line('No results!');
ELSE
dbms_output.Put_line('Results:');
FOR i IN enums.FIRST.. enums.LAST LOOP
dbms_output.Put_line(' Employee #'
||Enums(i)
||': '
||Names(i));
END LOOP;
END IF;
END;
BEGIN
-- Retrieve data for employees with Ids greater than 1000
SELECT employee_id,
last_name
BULK COLLECT INTO enums,names
FROM employees
WHERE employee_id > 1000;
-- The data has all been brought into memory by BULK COLLECT
-- No need to FETCH each row from the result set
Print_results();
-- Retrieve approximately 20% of all rows
SELECT employee_id,
last_name
BULK COLLECT INTO enums,names
FROM employees SAMPLE ( 20 );
Print_results();
END;
/



OUTPUT:-

No results!
Results:
Employee #200: Whalen
Employee #206: Gietz
Employee #100: King
Employee #104: Ernst
Employee #107: Lorentz
Employee #126: Mikkilineni
Employee #127: Landry
Employee #130: Atkinson
Employee #135: Gee
Employee #156: King
Employee #158: McEwen
Employee #163: Greene
Employee #168: Ozer
Employee #169: Bloom
Employee #170: Fox
Employee #171: Smith
Employee #173: Kumar
Employee #184: Sarchand
Employee #186: Dellinger
Employee #189: Dilly
Employee #193: Everett

PL/SQL procedure successfully completed.

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 :-