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 FORALL With BULK COLLECT

DROP TABLE emp_temp CASCADE CONSTRAINTS PURGE;

CREATE TABLE emp_temp
AS
SELECT *
FROM employees;

DECLARE
TYPE numlist IS TABLE OF NUMBER;
depts NUMLIST := Numlist(10,20,30);
TYPE enum_t IS TABLE OF employees.employee_id%TYPE;
TYPE dept_t IS TABLE OF employees.department_id%TYPE;
e_ids ENUM_T;
d_ids DEPT_T;
BEGIN
FORALL j IN depts.FIRST..depts.LAST
DELETE FROM emp_temp
WHERE department_id = Depts(j)
RETURNING employee_id,department_id BULK COLLECT INTO e_ids,d_ids;
dbms_output.Put_line('Deleted '
||SQL%ROWCOUNT
||' rows:');
FOR i IN e_ids.FIRST.. e_ids.LAST LOOP
dbms_output.Put_line('Employee #'
||E_ids(i)
||' from dept #'
||D_ids(i));
END LOOP;
END;
/



OUTPUT:-

Deleted 9 rows:
Employee #200 from dept #10
Employee #201 from dept #20
Employee #202 from dept #20
Employee #114 from dept #30
Employee #115 from dept #30
Employee #116 from dept #30
Employee #117 from dept #30
Employee #118 from dept #30
Employee #119 from dept #30

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