Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 577923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:12:21+00:00 2026-05-13T14:12:21+00:00

I am catching errors from a bulk insert operation like this: begin –bulk insert

  • 0

I am catching errors from a bulk insert operation like this:

begin
    --bulk insert
    forall i in v_data.first .. v_data.last save exceptions
        insert into my_filter_table values v_data (i);

    commit;

exception
    -- catch and print the saved-up DML errors.
    when X_DML_ERRORS then
        declare
            v_iteration number;
        begin
            dbms_output.put_line('');
            dbms_output.put_line('DML Errors:');
            for i in 1 .. SQL%BULK_EXCEPTIONS.count loop
                v_iteration := SQL%BULK_EXCEPTIONS(i).error_index;

                dbms_output.put_line('Iteration: '||v_iteration||' Message: '||
                                 SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));


            end loop;
        end;
end;

The output looks something like this:

    Iteration: 3 Message: ORA-01400: cannot insert NULL into ()
    Iteration: 4 Message: ORA-02290: check constraint (.) violated
    Iteration: 8 Message: ORA-00001: unique constraint (.) violated

The fact that I’m getting errors does not bother me, as I am testing error-handling code. The problem is that the Oracle error message is not displaying the the constraint names, i.e. it displays check constraint (.) violated but that doesn’t tell me WHICH check constraint I violated.

Does anyone know what’s up with this?

(Oracle version 10.2)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:12:21+00:00Added an answer on May 13, 2026 at 2:12 pm

    SQL%BULK_EXCEPTIONS(i).error_code only saves the Oracle error number. You are then using the sqlerrm function to look up the error message text. That function would have no way of knowing what constraint is being broken.

    You can call the sqlerrm function without an exception being thrown to duplicate your results.

    begin
       dbms_output.put_Line(sqlerrm(-1400));
       dbms_output.put_Line(sqlerrm(-2290));
       dbms_output.put_Line(sqlerrm(-1));
    end;
    

    Which outputs

    ORA-01400: cannot insert NULL into ()
    ORA-02290: check constraint (.) violated
    ORA-00001: unique constraint (.) violated
    

    A possible workaround would be to reexecute the failed statement in the exception handler.

    Table Def:

    create table t ( x number(1) primary key);
    

    Code:

    declare
       dml_errors EXCEPTION;
       PRAGMA EXCEPTION_INIT(dml_errors, -24381);
       TYPE t_nums is table of NUMBER;
       l_nums t_nums := t_nums(1,1,10);
    begin
       forall i in 1..l_nums.count save exceptions
          execute immediate 'insert into t values (:x)' using l_nums(i);
    exception
       when dml_errors then
          for j in 1..sql%bulk_exceptions.count
          loop
             if sql%bulk_exceptions(j).error_code = 1
             then
                begin
                   execute immediate 'insert into t values (:x)'
                      using l_nums(sql%bulk_exceptions(j).error_index);
                exception
                   when dup_val_on_index then
                      dbms_output.put_line(sqlerrm);
                end;
             else
                dbms_output.put_line(sqlerrm(-sql%bulk_exceptions(j).error_code));
             end if;
          end loop;
    end;
    

    Which outputs:

    ORA-01438: value larger than specified precision allowed for this column
    ORA-00001: unique constraint (XXXXXXXX.SYS_C00264470) violated
    ORA-24381: error(s) in array DML
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 381k
  • Answers 381k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Using .htaccess and redirecting the request, with something like: RewriteRule… May 14, 2026 at 10:19 pm
  • Editorial Team
    Editorial Team added an answer MKAnnotation is a protocol. So you need to write your… May 14, 2026 at 10:19 pm
  • Editorial Team
    Editorial Team added an answer Here's a quick hack that uses a barchart (axes.barh) to… May 14, 2026 at 10:19 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.