Skip to Main Content
  • Questions
  • Eexecute an Oracle stored procedure via a database link

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Vincent.

Asked: April 27, 2017 - 10:25 am UTC

Last updated: April 28, 2017 - 1:31 am UTC

Version: 12c

Viewed 10K+ times! This question is

You Asked

Hi,

I have procedure via database link, and getting this error

ORA-02064: distributed operation not supported

This is because need to apply pragma autonomous_transaction. But is there any other way? some of the procedure we need to reuse, and we only need to perform commit at last.

Is there any other way by not combine all logic into one procedure (it could be very messy).

Thank you.'

and Connor said...

In a distributed transaction -- one in which "DATABASE A" calls "DATABASE B", only "DATABASE A" may commit. The reason is "database B" has no mechanism for co-ordinating with "database a" on the commit. We need to do a 2 phase commit to ensure that when the transaction commits any work performed on DATABASE A is committed *as well as* any work on database b.

Because the problem is more complex in general when database A calls both database B and database C. Here, if database B (which has NO IDEA that database C is even involved) attempted to commit -- it would not be able to coordinate with database A and having no knowledge of the existence of database C in the transaction -- could not coordinate it either.

A common workaround is an optional parameter to the existing routine -- a commit flag (make it be something like:

p_do_not_commit boolean in default FALSE );

You will then seek out all commit and rollback statements in the affected routine and rewrite them as:

if ( NOT p_do_not_commit ) then
commit;
end if;

so the routine can be called locally or remotely, and the parameter set accordingly.

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Vincent Goh, April 28, 2017 - 4:56 am UTC

Thank you very much, it works.

Could have a short example?

A reader, April 28, 2017 - 5:41 am UTC


More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library