Demonstrate how to use DELETE with bulk processing. : bulk collect « PL SQL Statements « Oracle PL/SQL Tutorial

Oracle PL/SQL Tutorial
1. Introduction
2. Query Select
3. Set
4. Insert Update Delete
5. Sequences
6. Table
7. Table Joins
8. View
9. Index
10. SQL Data Types
11. Character String Functions
12. Aggregate Functions
13. Date Timestamp Functions
14. Numerical Math Functions
15. Conversion Functions
16. Analytical Functions
17. Miscellaneous Functions
18. Regular Expressions Functions
19. Statistical Functions
20. Linear Regression Functions
21. PL SQL Data Types
22. PL SQL Statements
23. PL SQL Operators
24. PL SQL Programming
25. Cursor
26. Collections
27. Function Procedure Packages
28. Trigger
29. SQL PLUS Session Environment
30. System Tables Data Dictionary
31. System Packages
32. Object Oriented
33. XML
34. Large Objects
35. Transaction
36. User Privilege
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL/SQL Tutorial » PL SQL Statements » bulk collect 
22. 17. 6. Demonstrate how to use DELETE with bulk processing.
SQL>
SQL>
SQL>
SQL> create table employee_history
  2          (
  3           empl_no                integer         primary key
  4          ,lastname               varchar2(20)    not null
  5          ,firstname              varchar2(15)    not null
  6          ,midinit                varchar2(1)
  7          ,street                 varchar2(30)
  8          ,city                   varchar2(20)
  9          ,state                  varchar2(2)
 10          ,zip                    varchar2(5)
 11          ,zip_4                  varchar2(4)
 12          ,area_code              varchar2(3)
 13          ,phone                  varchar2(8)
 14        ,company_name         varchar2(50)
 15          );

Table created.

SQL>
SQL>
SQL>
SQL> insert into employee_history(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(9,'OK','Joe','T','Ave','Kansas City','MO','65602','3658','415', '456-4563','A Inc');

row created.

SQL>
SQL> insert into employee_history(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(12,'Yes','Larry','T','Rd.','Newarkville','NJ','27377','3298','908', '123-7384','B Inc');

row created.

SQL>
SQL> insert into employee_history(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(13,'No','Cindy','T','13 Street','Warwick','RI','07377','3298','401', '123-7384','C Inc');

row created.

SQL>
SQL> insert into employee_history(empl_no,lastname,firstname,midinit,street,city,state,zip,zip_4,area_code,phone,company_name)
  2  values(14,'Fine','Doris','R','11th Ave','New York','NY','22299','3222','212', '123-1234','D Inc');

row created.

SQL>
SQL>
SQL>
SQL> create table ord(
  2           order_no               integer          primary key
  3          ,empl_no                integer
  4          ,order_date             date not null
  5          ,total_order_price      number(7,2)
  6          ,deliver_date           date
  7          ,deliver_time           varchar2(7)
  8          ,payment_method         varchar2(2)
  9          ,emp_no                 number(3,0)
 10          ,deliver_name           varchar2(35)
 11          ,gift_message           varchar2(100)
 12  );

Table created.

SQL>
SQL>
SQL> insert into ord(order_no,empl_no,order_date,total_order_price,deliver_date,deliver_time,payment_method,emp_no,deliver_name,gift_message)
  2           values(1,1,'14-Feb-2002', 23.00'14-Feb-2002', '12 noon', 'CA',1, null, 'Gift for wife');

row created.

SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time ,payment_method ,emp_no,deliver_name ,gift_message )
  2           values(2,1,'14-Feb-2003', 510.98'14-feb-2003', '5 pm', 'NY',7'Rose Ted', 'Happy Valentines Day to Mother');

row created.

SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values(32,'14-Feb-2004', 315.99'14-feb-2004', '3 pm', 'VS',2'Ani Forest', 'Happy Valentines Day to Father');

row created.

SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values(42,'14-Feb-1999', 191.95'14-feb-1999', '2 pm', 'NJ',2'O. John', 'Happy Valentines Day');

row created.

SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message    )
  2           values(56,'4-mar-2002', 101.95'5-mar-2002', '2:30 pm', 'MO'    2'Cora', 'Happy Birthday from John');

row created.

SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values(69,'7-apr-2003', 221.95'7-apr-2003', '3 pm', 'MA', 2'Sake Keith', 'Happy Birthday from Joe' );

row created.

SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values(79,'20-jun-2004', 315.95'21-jun-2004', '12 noon', 'BC', 2'Jessica Li', 'Happy Birthday from Jessica');

row created.

SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values (812'31-dec-1999', 135.95'1-jan-2000', '12 noon', 'DI',   3'Larry', 'Happy New Year from Lawrence');

row created.

SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values (912'26-dec-2003', 715.95'2-jan-2004', '12 noon', 'SK',7'Did', 'Happy Birthday from Nancy' );

row created.

SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values(104, sysdate-1119.95, sysdate+2'6:30 pm', 'VG',2'P. Jing', 'Happy Valentines Day to Jason');

row created.

SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values(112, sysdate, 310.00, sysdate+2'3:30 pm', 'DC',2'C. Late', 'Happy Birthday Day to Jack');

row created.

SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message)
  2           values(127, sysdate-3121.95, sysdate-2'1:30 pm', 'AC',2'W. Last', 'Happy Birthday Day to You');

row created.

SQL> insert into ord(order_no  ,empl_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message)
  2           values(137, sysdate, 211.95, sysdate-4'4:30 pm', 'CA',2'J. Bond', 'Thanks for hard working');

row created.

SQL>
SQL>
SQL>
SQL> -- First, review row-at-a-time processing:
SQL> declare
  2      type cust_array_type is table of number
  3           index by binary_integer;
  4      employee_array  cust_array_type;
  5  begin
  6      select empl_no bulk collect
  7      into employee_array from employee_history;
  8
  9      FOR i IN employee_array.FIRST..employee_array.LAST LOOP
 10         delete from ord where empl_no = employee_array(i);
 11         dbms_output.put_line(sql%rowcount);
 12      END LOOP;
 13  end;
 14  /
2
2
0
0

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL> drop table employee_history;

Table dropped.

SQL>
SQL> drop table ord;

Table dropped.
22. 17. bulk collect
22. 17. 1. select BULK COLLECT
22. 17. 2. Adding a limit to BULK COLLECT
22. 17. 3. To get the same result by using explicit cursors and bulk collect
22. 17. 4. Speeding Up Data Collection with Bulk Operations
22. 17. 5. Using the RETURNING ...BULK COLLECT clause to SELECT directly into a PL/SQL array
22. 17. 6. Demonstrate how to use DELETE with bulk processing.
22. 17. 7. Bulk processing with the FORALL statement
22. 17. 8. Bulk collect with non-cursor SELECT into multiple collections
22. 17. 9. Bulk collect from cursor with LIMIT option
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.