18M, is really small these days, could be done in few mins, not hours.
please check if this helps.
demo@ORA11G> create table testlarge as
2 select owner code,
3 object_type as state,
4 created as sdate,
5 cast(null as varchar2(1)) as flag
6 from big_table;
Table created.
demo@ORA11G>
demo@ORA11G> exec dbms_stats.gather_table_stats(user,'testlarge',degree=>2);
PL/SQL procedure successfully completed.
demo@ORA11G> select count(*) from testlarge;
COUNT(*)
----------
20000000
1 row selected.
demo@ORA11G>
demo@ORA11G> variable a1 varchar2(20)
demo@ORA11G> variable b1 varchar2(20)
demo@ORA11G> exec :a1 := '01/01/1990';
PL/SQL procedure successfully completed.
demo@ORA11G> exec :b1 := '08/23/2016';
PL/SQL procedure successfully completed.
demo@ORA11G> explain plan for
2 merge into testlarge t1 using (
3 select code ,count(*)
4 from testlarge
5 where STATE in ('TABLE SUBPARTITION','SYNONYM','JAVA CLASS','TABLE PARTITION')
6 and SDATE between to_date(:a1,'mm/dd/yyyy')
7 and to_date(:b1,'mm/dd/yyyy')
8 group by code
9 having count(*) > 1 ) t2
10 on (t1.code = t2.code)
11 when matched then
12 update set t1.flag ='Y'
13 where t1.STATE in ('TABLE SUBPARTITION','SYNONYM','JAVA CLASS','TABLE PARTITION')
14 and t1.SDATE between to_date(:a1,'mm/dd/yyyy') and
15 to_date(:b1,'mm/dd/yyyy');
Explained.
demo@ORA11G> @xplan
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------
Plan hash value: 3388205627
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | MERGE STATEMENT | | 1428K| 73M| 60901 (2)| 00:12:11 |
| 1 | MERGE | TESTLARGE | | | | |
| 2 | VIEW | | | | | |
|* 3 | HASH JOIN | | 1428K| 87M| 60901 (2)| 00:12:11 |
| 4 | VIEW | | 3 | 90 | 30527 (2)| 00:06:07 |
|* 5 | FILTER | | | | | |
| 6 | SORT GROUP BY | | 3 | 102 | 30527 (2)| 00:06:07 |
|* 7 | FILTER | | | | | |
|* 8 | TABLE ACCESS FULL| TESTLARGE | 5556 | 184K| 30526 (2)| 00:06:07 |
| 9 | TABLE ACCESS FULL | TESTLARGE | 20M| 648M| 30257 (1)| 00:06:04 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("T1"."CODE"="T2"."CODE")
5 - filter(COUNT(*)>1)
7 - filter(TO_DATE(:B1,'mm/dd/yyyy')>=TO_DATE(:A1,'mm/dd/yyyy'))
8 - filter(("STATE"='JAVA CLASS' OR "STATE"='SYNONYM' OR "STATE"='TABLE
PARTITION' OR "STATE"='TABLE SUBPARTITION') AND
"SDATE">=TO_DATE(:A1,'mm/dd/yyyy') AND "SDATE"<=TO_DATE(:B1,'mm/dd/yyyy'))
26 rows selected.
demo@ORA11G> set timing on
demo@ORA11G> merge into testlarge t1 using (
2 select code ,count(*)
3 from testlarge
4 where STATE in ('TABLE SUBPARTITION','SYNONYM','JAVA CLASS','TABLE PARTITION')
5 and SDATE between to_date(:a1,'mm/dd/yyyy')
6 and to_date(:b1,'mm/dd/yyyy')
7 group by code
8 having count(*) > 1 ) t2
9 on (t1.code = t2.code)
10 when matched then
11 update set t1.flag ='Y'
12 where t1.STATE in ('TABLE SUBPARTITION','SYNONYM','JAVA CLASS','TABLE PARTITION')
13 and t1.SDATE between to_date(:a1,'mm/dd/yyyy') and
14 to_date(:b1,'mm/dd/yyyy');
17123270 rows merged.
Elapsed: 00:03:41.19
demo@ORA11G> commit;
Commit complete.
Elapsed: 00:00:01.80
demo@ORA11G>