Ask the Expert

How to call a procedure in a procedure

I have a procedure p1. How do I get user values to it at run time? How do I call another procedure p2 from p1?

    Requires Free Membership to View

When you create a procedure, you can declare input/output variables. Take a look at this simple procedure:

CREATE PROCEDURE p1 (x IN NUMBER, y OUT VARCHAR2)
AS 
BEGIN
   DBMS_OUTPUT.PUT_LINE('x='||x);
   y:=x;
   p2(y);
END;
/

In the same procedure above, I can obtain the value of "x" at runtime simply by referring to it in my code. My call to DBMS_OUTPUT.PUT_LINE just references the x variable. Similarly, I assign the value of x to the variable y. Since 'y' is defined as an output variable to the procedure, the calling program can see the changes to this variable.

Calling a procedure in a procedure is as simple as stating the procedure's name and supplying any necessary arguments. In my example above, I call procedure P2 and pass the variable "y" to it.

This was first published in January 2008

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: