Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask PL-SQL Expert

How Bulk Binds Improve Performance

The assigning of values to the PL/SQL variables in SQL statements is known as binding.

The binding of the whole collection at once is known as the bulk binding. The Bulk binds improve performance by minimizing the number of the context switches between the PL/SQL and SQL engines. With the bulk binds, whole collections, not just an individual element, are passed back and forth. For illustration, the DELETE statement below is sent to the SQL engine just once, with the whole nested table:

DECLARE

TYPE NumList IS TABLE OF NUMBER;

mgrs NumList := NumList(7566, 7782, ...); -- manager numbers

BEGIN

...

FORALL i IN mgrs.FIRST..mgrs.LAST

DELETE FROM emp WHERE mgr = mgrs(i);

END;

In the illustration below, 5000 part numbers and names are loaded into the index-by tables. Then, all the table elements are inserted into a database table twice. At First, they are inserted using a FOR loop, that completes in 38 seconds. Then, they are bulk-inserted by using a FORALL statement that completes in only 3 seconds.

SQL> SET SERVEROUTPUT ON

SQL> CREATE TABLE parts (pnum NUMBER(4), pname CHAR(15));

Table created.

SQL> GET test.sql

1 DECLARE

2 TYPE NumTab IS TABLE OF NUMBER(4) INDEX BY BINARY_INTEGER;

3 TYPE NameTab IS TABLE OF CHAR(15) INDEX BY BINARY_INTEGER;

4 pnums NumTab;

5 pnames NameTab;

6 t1 CHAR(5);

7 t2 CHAR(5);

8 t3 CHAR(5);

9 PROCEDURE get_time (t OUT NUMBER) IS

10 BEGIN SELECT TO_CHAR(SYSDATE,'SSSSS') INTO t FROM dual; END;

11 BEGIN

12 FOR j IN 1..5000 LOOP -- load index-by tables

13 pnums(j) := j;

14 pnames(j) := 'Part No. ' || TO_CHAR(j); 15 END LOOP;

16 get_time(t1);

17 FOR i IN 1..5000 LOOP -- use FOR loop

18 INSERT INTO parts VALUES (pnums(i), pnames(i));

19 END LOOP;

20 get_time(t2);

21 FORALL i IN 1..5000 -- use FORALL statement

22 INSERT INTO parts VALUES (pnums(i), pnames(i));

23 get_time(t3);

24 DBMS_OUTPUT.PUT_LINE('Execution Time (secs)');

25 DBMS_OUTPUT.PUT_LINE('---------------------');

26 DBMS_OUTPUT.PUT_LINE('FOR loop: ' || TO_CHAR(t2 - t1));

27 DBMS_OUTPUT.PUT_LINE('FORALL: ' || TO_CHAR(t3 - t2));

28* END;

SQL> /

Execution Time (secs)

---------------------

FOR loop: 38

FORALL: 3

PL/SQL process successfully completed.

In the bulk-bind input collections, you can use the FORALL statement. And in the bulk-bind output collections, you can use the BULK COLLECT clause.

PL-SQL, Programming

  • Category:- PL-SQL
  • Reference No.:- M9510263

Have any Question?


Related Questions in PL-SQL

For this assignment you will be provided a database backup

For this assignment, you will be provided a database backup for a database called FinanceDB. You will have to restore this backup to your own version of SQL Server. All of the questions in this assignment relate to the F ...

Complete the following tasksin microsoft access create the

Complete the following tasks: In Microsoft Access, create the database and tables that you identified in W3 Assignment 2. In Microsoft Word, write the SQL statements to create the database and tables. Write SQL statement ...

Purpose of the assessment with ulo mapping the purpose of

Purpose of the assessment (with ULO Mapping) The purpose of this assignment is to develop skills in managing data in databases and to gain understanding of data model development and implementation using a commercially a ...

Assignment - queries functions and triggersaimthe aims of

Assignment - Queries, Functions and Triggers Aim The aims of this assignment are to: formulate SQL queries; populate an RDBMS with a real dataset, and analyse the data; design test data for testing SQL queries; create SQ ...

Continuing the project you have worked on in weeks 1-4 in

Continuing the project you have worked on in Weeks 1-4, in this final week, complete the following tasks: Refine your database and SQL statements by incorporating your instructor's feedback. Verify that the database comp ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As