. . . sal_raise(emp_id, 200); . . .
This line calls the SAL_RAISE procedure. EMP_ID is a variable within the context of the procedure. Note that recursive procedure calls are allowed within PL/SQL; that is, a procedure can call itself.
BEGIN sal_raise(1043, 200); END;
Note: Interactive tools such as SQL*Plus require that you follow these lines with a slash (/) to execute the PL/SQL block.
An easier way to execute a block is to use the SQL*Plus command EXECUTE, which effectively wraps BEGIN and END statements around the code you enter. For example:
EXECUTE sal_raise(1043, 200);
Some interactive tools allow session variables to be created. For example, when using SQL*Plus, the following statement creates a session variable:
VARIABLE assigned_empno NUMBER
Once defined, any session variable can be used for the duration of the session. For example, you might execute a function and capture the return value using a session variable:
EXECUTE :assigned_empno := hire_emp('JSMITH', 'President', \ 1032, SYSDATE, 5000, NULL, 10); PRINT assigned_empno; ASSIGNED_EMPNO -------------- 2893
See the SQL*Plus User's Guide and Reference for SQL*Plus information. See your tools manual for information about performing similar operations using your development tool.
To execute a procedure within a PL/SQL block in an application, simply call the procedure. The following line within a PL/SQL block calls the FIRE_EMP procedure:
fire_emp(:empno);
In this case, :EMPNO is a host (bind) variable within the context of the application.
To execute a procedure within the code of a precompiler application, you must use the EXEC call interface. For example, the following statement calls the FIRE_EMP procedure in the code of a precompiler application:
EXEC SQL EXECUTE BEGIN fire_emp(:empno); END; END-EXEC;
:EMPNO is a host (bind) variable.
For more information about calling PL/SQL procedures from within 3GL applications, see the following manuals:
EXECUTE jward.fire_emp (1043); EXECUTE jward.hire_fire.fire_emp (1043);
Attention: A stored subprogram or package executes in the privilege domain of the owner of the procedure. The owner must have been explicitly granted the necessary object privileges to all objects referenced within the body of the code.
sal_raise(7369, 500); sal_raise(sal_incr=>500, emp_id=>7369); sal_raise(7369, sal_incr=>500);
The first statement identifies the argument values by listing them in the order in which they appear in the procedure specification.
The second statement identifies the argument values by name and in an order different from that of the procedure specification. If you use argument names, you can list the arguments in any order.
The third statement identifies the argument values using a combination of these methods. If you use a combination of order and argument names, values identified in order must precede values identified by name.
If you have used the DEFAULT option to define default values for IN parameters to a subprogram (see the PL/SQL User's Guide and Reference), you can pass different numbers of actual parameters to the 1subprogram, accepting or overriding the default values as you please. If an actual value is not passed, the corresponding default value is used. If you want to assign a value to an argument that occurs after an omitted argument (for which the corresponding default is used), you must explicitly designate the name of the argument, as well as its value.
EXECUTE fire_emp@NY(1043);
For information on exception handling when calling remote procedures, see .
CREATE PROCEDURE fire_emp(emp_id NUMBER) IS BEGIN DELETE FROM emp@sales WHERE empno = emp_id; END;
The list below explains how to properly call remote procedures, depending on the calling environment.
CREATE PROCEDURE local_procedure(arg1, arg2) AS BEGIN ... remote_procedure@dblink(arg1, arg2); ... END;
CREATE PROCEDURE local_procedure(arg1, arg2) AS BEGIN ... synonym(arg1, arg2); ... END;
Warning: Unlike stored procedures, which use compile-time binding, when referencing remote procedures, runtime binding is used. 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, the work done by the remote procedure is also rolled back. A procedure called remotely cannot execute a COMMIT, ROLLBACK, or SAVEPOINT statement.
A distributed update modifies data on two or more nodes. A distributed update is possible using a procedure that includes two or more remote updates that access data on different nodes. Statements in the construct are sent to the remote nodes and the execution of the construct succeeds or fails as a unit. If part of a distributed update fails and part succeeds, 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, the remote procedure is not executed and the local procedure is invalidated.