How bulk bind helps improvement in performance?, PL-SQL Programming

Assignment Help:

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.


Related Discussions:- How bulk bind helps improvement in performance?

Use the pls_integer datatype - performance of application, Use the PLS_INTE...

Use the PLS_INTEGER Datatype When you require to declare an integer variable, use the datatype PLS_INTEGER that is the most efficient numeric type. That is as the PLS_INTEGER

Boolean values-assignments in pl/sql, Boolean Values Only the values TRU...

Boolean Values Only the values TRUE, FALSE, & NULL can be assigned to a Boolean variable. For illustration, given the declaration DECLARE done BOOLEAN; the following statements

Max and min operator in sql, MAX and MIN operator in SQL Example: ...

MAX and MIN operator in SQL Example: (SELECT MAX (Mark) FROM EXAM_MARK WHERE StudentId = 'S1') (SELECT MIN (Mark) FROM EXAM_MARK WHERE StudentId = 'S1') Example

Need azure crm web application with authentication, Need Azure CRM Web Appl...

Need Azure CRM Web Application with two-factor authentication We presently have a CRM-like database stored on MS Azure that we presently access over an MS Access application. It

Database values-assignments in pl/sql, Database Values You can use the S...

Database Values You can use the SELECT statement to have the Oracle assign values to a variable. For Each and every item in the select list, there must be a matching, type-compa

Example of when or then constraints - sql, Example of WHEN or THEN Constrai...

Example of WHEN or THEN Constraints A concrete example showing how SQL supports WHEN/THEN constraints CREATE TABLE SAL_HISTORY (EmpNo CHAR (6), Salary INTEGER NOT NULL,

Create a procedure to tax calculation task, Complete the following steps to...

Complete the following steps to create a procedure to calculate the tax on an order. The BB_TAX table contains the states that require taxes to be submitted for Internet sales. If

Best practices/Data Warhousing, What are 3 good practices of modeling and/o...

What are 3 good practices of modeling and/or implementing data warehouses?

Using savepoints, Using Savepoints The scope of the savepoint is a tra...

Using Savepoints The scope of the savepoint is a transaction in which it is defined. The Savepoints defined in the major transaction are not related to the savepoints defined

In packages - subprograms, In Packages The Forward declarations also g...

In Packages The Forward declarations also group logically related subprograms in the package. The subprogram specifications go in the package specification, & the subprogram b

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd