05.11.2015 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 8 ■ TRANSACTIONS 271<br />

last_ddl_time = last_ddl_time + 1;<br />

If we halted the UPDATE loop partway through, how would we restart it? We could not just<br />

rerun it, as we would end up adding 2 to some dates, <strong>and</strong> 1 to others. If we fail again, we would<br />

add 3 to some, 2 to others, 1 to the rest, <strong>and</strong> so on. We need yet more complex logic—some<br />

way to “partition” the data. For example, we could process every OBJECT_NAME that starts with A,<br />

<strong>and</strong> then B, <strong>and</strong> so on:<br />

ops$tkyte@ORA10G> create table to_do<br />

2 as<br />

3 select distinct substr( object_name, 1,1 ) first_char<br />

4 from T<br />

5 /<br />

Table created.<br />

ops$tkyte@ORA10G> begin<br />

2 for x in ( select * from to_do )<br />

3 loop<br />

4 update t set last_ddl_time = last_ddl_time+1<br />

5 where object_name like x.first_char || '%';<br />

6<br />

7 dbms_output.put_line( sql%rowcount || ' rows updated' );<br />

8 delete from to_do where first_char = x.first_char;<br />

9<br />

10 commit;<br />

11 end loop;<br />

12 end;<br />

13 /<br />

22257 rows updated<br />

1167 rows updated<br />

135 rows updated<br />

1139 rows updated<br />

2993 rows updated<br />

691 rows updated<br />

...<br />

2810 rows updated<br />

6 rows updated<br />

10 rows updated<br />

2849 rows updated<br />

1 rows updated<br />

2 rows updated<br />

7 rows updated<br />

PL/SQL procedure successfully completed.<br />

Now, we could restart this process if it fails, since we would not process any object name<br />

that had already been processed successfully. The problem with this approach, however, is<br />

that unless we have some attribute that evenly partitions the data, we will end up having a

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

Saved successfully!

Ooh no, something went wrong!