Introducing arrays and bulk operations
In this recipe, we will see different ways to insert data in our tables and we will make some considerations about the INSERT
statement's performance.
We will see how arrays can be used to speed up insert and select statements, and why it may be better to use a single statement to achieve certain goals than using a procedural approach.
How to do it...
The following steps will demonstrate the use of arrays to insert data into the tables:
Connect to the
SH
schema:CONNECT sh@TESTDB/sh
Create an empty table called
MY_SALES
with the same structure as theSALES
table:CREATE TABLE sh.MY_SALES AS SELECT cust_id, prod_id FROM sh.sales WHERE 1=0;
Enable timing:
SET TIMING ON
Create a PL/SQL block to insert the sales of the second half of year 2001 from the
SALES
table to the new table using a cursor to scroll theSALES
table:DECLARE CURSOR curs_c1 IS SELECT cust_id, prod_id FROM sh.sales WHERE time_id between TO_DATE('20010701', 'YYYYMMDD') AND...