05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

644<br />

CHAPTER 14 ■ PARALLEL EXECUTION<br />

big_table-ORA10G> create table t2<br />

2 as<br />

3 select object_id id, object_name text, 0 session_id<br />

4 from big_table<br />

5 where 1=0;<br />

Table created.<br />

We are going to use the job queues built into the database to parallel process our procedure.<br />

We will schedule some number of jobs. Each job is our procedure slightly modified to<br />

just process the rows in a given rowid range.<br />

■Note In <strong>Oracle</strong> 10g, you could use the scheduler for something this simple, but in order to make the<br />

example 9i compatible, we’ll use the job queues here.<br />

To efficiently support the job queues, we’ll use a parameter table to pass inputs to our jobs:<br />

big_table-ORA10G> create table job_parms<br />

2 ( job number primary key,<br />

3 lo_rid rowid,<br />

4 hi_rid rowid<br />

5 )<br />

6 /<br />

Table created.<br />

This will allow us to just pass the job ID into our procedure, so it can query this table to<br />

get the rowid range it is to process. Now for our procedure. The code in bold is the new code<br />

we’ll be adding:<br />

big_table-ORA10G> create or replace<br />

2 procedure serial( p_job in number )<br />

3 is<br />

4 l_rec job_parms%rowtype;<br />

5 begin<br />

6 select * into l_rec<br />

7 from job_parms<br />

8 where job = p_job;<br />

9<br />

10 for x in ( select object_id id, object_name text<br />

11 from big_table<br />

12 where rowid between l_rec.lo_rid<br />

13 <strong>and</strong> l_rec.hi_rid )<br />

14 loop<br />

15 -- complex process here<br />

16 insert into t2 (id, text, session_id )<br />

17 values ( x.id, x.text, p_job );<br />

18 end loop;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!