2

When I run the PL/SQL block after the CREATE statement, I receive the duplicate key error I would expect if I did not add the hint. Any ideas to why the hint does not work?

CREATE TABLE Sandbox.Clue
(
    ID number,
    Clue_Name varchar2(8 BYTE),
    Quantity number,
        PRIMARY KEY (ID)
);

DECLARE
    i number := 1;
BEGIN
    for i in 1 .. 10
    loop
        INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(Sandbox.Clue.ID)*/ INTO Sandbox.Clue
        (
            ID, Clue_Name, Quantity
        )
        VALUES
        (
            mod(i, 2), 'Tip', 44
        );
    end loop;
END;
2
  • 4
    What does select * from v$version give you? That hint was introduced in 11.2. Before that version it's not available.
    – user1822
    Commented Aug 1, 2012 at 6:51
  • I am, indeed, using version 11.2.
    – user10478
    Commented Aug 2, 2012 at 20:14

4 Answers 4

4

The hint you specified was almost correct. In the hint you should specify the correct index_name, or the column list. Given the fact that the index_name is system generated, I would specify the column list.

DECLARE
    i number := 1;
BEGIN
    for i in 1 .. 10
    loop
        INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(Clue(ID))*/ INTO Clue
        (
            ID, Clue_Name, Quantity
        )
        VALUES
        (
            mod(i, 3), 'Tip', 44
        );
    end loop;
END;
/

also see Oracle® Database SQL Language Reference

3
  • Interesting, the hint appears to work only when the table name is NOT qualified by the schema name. I assume you noticed the same, as you omitted schema name completely from the code.
    – user10478
    Commented Aug 2, 2012 at 20:13
  • INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(Clue(ID))*/ INTO Sandbox.Clue
    – user10478
    Commented Sep 2, 2012 at 17:49
  • @user10478 The syntax for the table(column) part of the hint looks similar to that used for the index hint, for which the documentation states to specify the table name without schema name, or the alias if one is used. I'm not sure whether aliases are accepted for single table inserts (the docs suggest that they are) but it would be interesting to see whether the hint needs the alias to be used if one is specified. Commented Jun 11, 2013 at 9:45
2

Your syntax will need either:

table_name,index_name or
table_name(column_name)

in the hint, not just the column name as you have in your example.

1
  • @dezso it shows the syntax explicitly. anony_mouse: I've removed the comment about the link as ypercube has edited in the code. Commented Aug 8, 2012 at 12:27
0

In APEX, where a user can actually log into a particular schema (thus qualifying table names is optional), the follow code works while logged into Sandbox...

DECLARE
    i number := 1;
BEGIN
    for i in 1 .. 10
    loop
        INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(Clue(ID))*/ INTO Sandbox.Clue
        (
            ID, Clue_Name, Quantity
        )
        VALUES
        (
            mod(i, 3), 'Tip', 44
        );
    end loop;
END;

...however, the following code does not work in the same environment...

DECLARE
    i number := 1;
BEGIN
    for i in 1 .. 10
    loop
        INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(Sandbox.Clue(ID))*/ INTO Sandbox.Clue
        (
            ID, Clue_Name, Quantity
        )
        VALUES
        (
            mod(i, 3), 'Tip', 44
        );
    end loop;
END;

...while the single qualification is the only difference. I also attempted Sandbox(Clue(ID)) inside the hint, which was equally unsuccessful.

0

Please be aware of BUG#11865420 and BUG#17397545 as duplicates still might be inserted when using the IGNORE_ROW_ON_DUPKEY_INDEX-hint.

I would rather NOT use the hint until the issue on BUG#17397545 has been fixed (and confirmed).

1
  • 1
    Could you add some links to help readers with these bug reports? Commented Sep 3, 2013 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.