Call remote procedures using an appropriate database link and the procedure name. The following SQL*Plus statement runs the procedure Fire_emp located in the database and pointed to by the local database link named BOSTON_SERVER:
EXECUTE fire_emp1@boston_server(1043);
You must explicitly pass values to all remote procedure parameters, even if there are defaults. You cannot access remote package variables and constants.
Remote objects can be referenced within the body of a locally defined procedure. The following procedure deletes a row from the remote employee table:
CREATE OR REPLACE PROCEDURE fire_emp(emp_id NUMBER) IS BEGIN DELETE FROM emp@boston_server WHERE empno = emp_id; END;
The following list explains how to properly call remote procedures, depending on the calling environment.
CREATE OR REPLACE PROCEDURE local_procedure(arg IN NUMBER) AS BEGIN fire_emp1@boston_server(arg); END;
CREATE SYNONYM synonym1 for fire_emp1@boston_server; CREATE OR REPLACE PROCEDURE local_procedure(arg IN NUMBER) AS BEGIN synonym1(arg); END;
DECLARE arg NUMBER; BEGIN local_procedure(arg); END;
Here, local_procedure is defined as in the first item of this list.
Caution:
Unlike stored procedures, which use compile-time binding, runtime binding is used when referencing remote procedures. The user account to which you connect depends on the database link.
All calls to remotely stored procedures are assumed to perform updates; therefore, this type of referencing always requires two-phase commit of that transaction (even if the remote procedure is read-only). Furthermore, if a transaction that includes a remote procedure call is rolled back, then the work done by the remote procedure is also rolled back.
A procedure called remotely can usually execute a COMMIT, ROLLBACK, or SAVEPOINT statement, the same as a local procedure. However, there are some differences in behavior:
A distributed update modifies data on two or more databases. A distributed update is possible using a procedure that includes two or more remote updates that access data on different databases. Statements in the construct are sent to the remote databases, and the execution of the construct succeeds or fails as a unit. If part of a distributed update fails and part succeeds, then a rollback (of the entire transaction or to a savepoint) is required to proceed. Consider this when creating procedures that perform distributed updates.
Pay special attention when using a local procedure that calls a remote procedure. If a timestamp mismatch is found during execution of the local procedure, then the remote procedure is not run, and the local procedure is invalidated.
Synonyms can be created for standalone procedures and packages to do the following:
When a privileged user needs to call a procedure, an associated synonym can be used. Because the procedures defined within a package are not individual objects (the package is the object), synonyms cannot be created for individual procedures within a package.
Calling Stored Functions from SQL Expressions >>