Ask the Expert

Calling variable name packages

I want to call variable name packages because the name of the package changes in some states. For example:
 if i = 1 then exm_pck.pr_exm(x,x)
 elsif i = 2 then exm_pck.pr_exm(x,x)
The names of the packages and the states are in the a table.
 select pck_name , state_name
 into v_pck_name, v_state_name
 from xxx_table
 where state_name = 'XXX'
How can I call the v_pck_name without using a dynamic SQL command?

    Requires Free Membership to View

In your PL/SQL block, you can use a simple IF-THEN-ELSE statement to choose how to call a stored procedure, based on a value you have. To illustrate, look at the following sample code:

  SELECT pck_name, state_name INTO v_pck_name,
  FROM xxx_table
  WHERE state_name='XXX';
-- Depending on package name, run the appropriate package
  IF (v_pck_name='PKG1') THEN
  ELSIF (v_pck_name='PKG2') THEN
     DBMS_OUTPUT.PUT_LINE('No valid package');
It should be easy to see how the IF-THEN-ELSE is used to determine which package to use.

For More Information

This was first published in May 2003

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: