A private procedure in PL/SQL is a procedure that is declared inside a package body but not exposed in the package specification. It can only be called within the package and not from outside.
Example:
CREATE OR REPLACE PACKAGE my_package AS
PROCEDURE public_proc; -- Only public procedure is declared here
END my_package;
/
CREATE OR REPLACE PACKAGE BODY my_package AS
-- Private procedure (not declared in package spec)
PROCEDURE private_proc IS
BEGIN
DBMS_OUTPUT.PUT_LINE('This is a private procedure');
END private_proc;
-- Public procedure that can call the private one
PROCEDURE public_proc IS
BEGIN
private_proc; -- Private procedure is called within the package
END public_proc;
END my_package;
/
How to call a private procedure?
• Directly calling private_proc from outside will fail.
• You must call the public procedure (public_proc), which internally calls the private procedure:
EXEC my_package.public_proc;
No comments:
Post a Comment