Oracle 11g now has a feature to silently allow
insert SQL to accept duplicates with the ignore_row_on_dupkey_index
hint. When ignore_row_on_dupkey_index hint is used
in a SQL insert on a table with a unique key index, all duplicates will be
silently ignored, rather than causing the traditional error,
ORA-00001 unique constraint violated.
The Oracle docs note that the
ignore_row_on_dupkey_index are unlike any other hints because they have
an effect on the semantics of the SQL statement, actually changing the
functionality of the DML statament:
The change_dupkey_error_index,
ignore_row_on_dupkey_index, and retry_on_row_change hints are
unlike other hints in that they have a semantic effect.
The general philosophy explained in "Hints" does not apply
for these three hints.
The ignore_row_on_dupkey_index hint is also unique because unlike a
regular hint (hints are embedded inside comments), you will get an error.
In traditional SQL hints, hints with syntax, semantic or resource errors
will cause the hint to be ignored.
However, this hint will cause an ORA-38912 error if you don't pass
the correct arguments. Note that the ignore_row_on_dupkey_index
hint requires two arguments, the table name and index name. If the
index name is omitted, the ORA-38912 error is thrown:
insert /*+
ignore_row_on_dupkey_index(unique_cust) */
into
unique_cust
(select * from non_unique_cust);
ORA-38912: An index must be specified in the index
hint
Cause: Index specification was missing in
an ignore_row_on_dupkey_index or change_dupkey_error_index hint.
Action: In the hint, specify a unique index that
exists on the table.
Functionally, the
ignore_row_on_dupkey_index hint is somewhat similar to the SQL
merge
statement because it ignores duplicates on insert.
Examples of using the
ignore_row_on_dupkey_index
hint
Here is an example of using this hint to load a unique table from a
non-unique table, while preventing aborts due to duplicate values:
insert /*+
ignore_row_on_dupkey_index(unique_cust, unique_cust_pk_idx) */
into
unique_cust
(select * from non_unique_cust);
|
|
Get the Complete
Oracle SQL Tuning Information
The landmark book
"Advanced Oracle
SQL Tuning The Definitive Reference" is
filled with valuable information on Oracle SQL Tuning.
This book includes scripts and tools to hypercharge Oracle 11g
performance and you can
buy it
for 30% off directly from the publisher.
|