How Does Oracle limit the process of illegal package calling?

Source: Internet
Author: User

How Does Oracle limit the process of illegal package calling?

How Does Oracle limit the process of illegal package calling?

Assume that I have a package P_A, which encapsulates the important process DO_A.
Another package P_ B needs to call P_A.DO_A to implement important business logic.
I want to authorize only the package P_ B to call. I think it is illegal to call P_A.DO_A through other methods!
The following is a solution provided by PL/SQL development guru [forelstan:

Create or replace package p_a IS
PROCEDURE do_a;
END p_a;
/

Create or replace package body p_a IS
PROCEDURE do_a IS
BEGIN
Dbms_output.put_line ('Do _ a from P_A ');
END do_a;
END p_a;
/

Create or replace package P_ B
IS
PROCEDURE DO_ B;
END P_ B;
/

Create or replace package body P_ B
IS
PROCEDURE DO_ B
IS
BEGIN
P_A.DO_A;
END DO_ B;
END P_ B;
/

BEGIN
P_A.DO_A;-The call is considered invalid.
P_ B .DO_ B;-unique and valid call
END;
/

-How can I limit that only P_ B can be called with P_A.DO_A?
-Before 12c, we used DBMS_UTILITY. FORMAT_CALL_STACK
-Write custom functions:
Create or replace function I _was_called_by (program_in IN VARCHAR2)
RETURN BOOLEAN
IS
C_stack CONSTANT VARCHAR2 (32767)
: = DBMS_UTILITY.format_call_stack;
BEGIN
Return instr (SUBSTR (c_stack,
INSTR (c_stack,
CHR (10), 1, 5) + 1,
INSTR (c_stack, CHR (10), 1, 6)
-INSTR (c_stack, CHR (10), 1, 5)
+ 1 ),
Program_in)> 0;
END;

-- PL/SQL Call Stack --
Object line object
Handle number name
000007FF50456200 4 function SCOTT. I _WAS_CALLED_BY
000007FF504ADD28 4 package body SCOTT. P_A
000007FF50439820 2 anonymous block

-Modify P_A.DO_A:
PROCEDURE DO_A
IS
BEGIN
IF I _was_called_by ('P _ B ')
THEN
Dbms_output.put_line ('Do _ a from P_A ');
ELSE
RAISE_APPLICATION_ERROR (-20209, 'invalid call! ');
End if;
END;
/

-Invocation discovery again
BEGIN
*
Row 3 has an error:
ORA-20209: Illegal call!
ORA-06512: In SCOTT. P_A, line 7
ORA-06512: In line 2

-After 12c, we use the accessible by condition of the package.
-Modify the description of package P_A
Create or replace package p_a
Accessible by (P_ B)
IS
PROCEDURE do_a;
END p_a;
/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.