简体   繁体   中英

PL/SQL package - calling a procedure within a package

I am a pl/sql beginner trying to understand how to call procedure within the same package. This is a sample package body with 2 procedures. First is for creating an employee and second is creating an employee card if the emp_id is not empty. Can you please advice me how to proceed in the if statement block down below?

Thanks a lot!

create or replace PACKAGE BODY sample_package
IS
PROCEDURE create_employee(
    emp_id IN OUT VARCHAR2,
    emp_name IN VARCHAR2,
    emp_surname IN VARCHAR2)
IS
BEGIN
    schema.package.procedure(
        emp_id,
        emp_name,
        emp_surname
    );

    IF (emp_id != null) THEN
        --how do I call procedure create_id_card
    END IF;
END;

PROCEDURE create_id_card(
    card_id IN OUT VARCHAR2,
    card_name IN VARCHAR2)
IS
BEGIN
    schema.package.procedure(
        card_id,
        card_name
    );
END;
END sample_package;

As simple as that:

IF (emp_id is not null) THEN
    --how do I call procedure create_id_card
    create_id_card(parameter1, parameter2);
END IF;

As both procedures are in the same package, you don't have to do anything (precede its name with package or owner names, if that's what you meant).

I don't know which parameters you're actually passing so I named them just parameter_x .

You have to find a way of passing variables card_id and card_name in the procedure create_employee like the below

  PROCEDURE create_employee(
 emp_id IN OUT VARCHAR2,
 emp_name IN VARCHAR2,
 emp_surname IN VARCHAR2)
 IS
 l_card_id VARCHAR2(100);
 l_card_name VARCHAR2(255);
 BEGIN
schema.package.procedure(
    emp_id,
    emp_name,
    emp_surname
);

l_card_name:=emp_name;

IF emp_id is not null THEN
    create_id_card(l_card_id, l_card_name);
END IF;
END;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM