Question

I have a procedure to insert records through a select statement. I need my procedure to perform something if the insert fails or completes. How can I let my procedure know if an insert is completed or failed?

Currently I am matching the count between fetched data and loaded data. If they match, then I take it as completed.(not sure if this approach is the most efficient) What if the load fails for whatever reason, how I do trap that?

Thanks

Was it helpful?

Solution

You need to trap exceptions and provide a useful handler. Perhaps something like the following:

BEGIN
  INSERT INTO SOME_TABLE (A_COLUMN) VALUES ('XYZ');
EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Error: ' || SQLCODE || ':' || SQLERRM);
    RAISE;
END;

The exception handler begins with the line containing EXCEPTION.

There are many pre-defined exceptions that either you or the Oracle system can raise, and you can define your own exceptions and use them. The link given in the comment above should be helpful in understanding this concept.

Share and enjoy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top