In PL/SQL, you can capture an OUT parameter from one procedure and pass it to another procedure by using PL/SQL variables. Below is an example demonstrating this process:
Example: Catching OUT parameter and calling another procedure
- Procedure 1: Returns an output parameter.
- Procedure 2: Accepts the output of Procedure 1 as an input parameter.
Step 1: Create First Procedure (with OUT parameter)
Step 2: Create Second Procedure (Takes OUT parameter as INPUT)
Step 3: Call Procedures in an Anonymous Block
Explanation:
get_employee_salary
fetches the salary based on the Employee ID and returns it via an OUT parameter (p_salary
).process_salary
receives the Employee ID and the salary from the first procedure and logs it into theSALARY_AUDIT
table.- The anonymous PL/SQL block calls Procedure 1, stores the result in
v_salary
, and then passes it to Procedure 2.
Key Points to Remember:
- OUT parameters are used to return values from a procedure.
- When calling a procedure with an OUT parameter, the calling program must declare a variable to store the returned value.
- The captured OUT parameter value can then be used to call another procedure.
Tags:
Oracle