如何在 Oracle 包中执行私有过程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/924490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:54:03  来源:igfitidea点击:

How do I execute private procedures in an Oracle package?

oracleplsql

提问by Margaret

This is my first attempt at creating a package, so I must be missing something really really obvious (nothing that I've Googled for seems to even consider it worth mentioning).

这是我第一次尝试创建一个包,所以我一定遗漏了一些非常明显的东西(我在谷歌上搜索的任何东西似乎都认为值得一提)。

Obviously, if you have procedures in your package body that are not included in the specification section, then those procedures are private. The problem I've got is that I can't seem to figure out how to referencethose private packages once I've made them. And SQL Developer refuses to give me any message more useful than 'execution completed with warning', which doesn't help...

显然,如果您的包主体中有未包含在规范部分中的过程,则这些过程是私有的。我遇到的问题是,一旦我制作了它们,我似乎无法弄清楚如何引用这些私有包。并且 SQL Developer 拒绝给我任何比“执行完成并警告”更有用的消息,这无济于事......

As an example, this is what I've been trying that doesn't work (just throws the aforementioned compiler error):

例如,这是我一直在尝试但不起作用的方法(只是抛出上述编译器错误):

CREATE OR REPLACE PACKAGE BODY testPackage AS

PROCEDURE privateProc; --Forward declaration

PROCEDURE publicProc IS
BEGIN
    EXECUTE privateProc();
END;

PROCEDURE privateProc IS
BEGIN
    DBMS_OUTPUT.PUT_LINE('test');
END;

END testPackage;

I've also tried referring to it as testPackage.privateProc, which hasn't worked either.

我也试过将其称为testPackage.privateProc,但也没有用。

What am I doing wrong?

我究竟做错了什么?

回答by Martlark

I think you should do this:

我认为你应该这样做:

CREATE OR REPLACE PACKAGE BODY testPackage AS
PROCEDURE privateProc; --Forward declaration

PROCEDURE publicProc IS
  BEGIN    
    privateProc();
END;

PROCEDURE privateProc IS
BEGIN    
  DBMS_OUTPUT.PUT_LINE('test');
END;
END testPackage;

Just call privateProc as if it is part of the language. Execute is for running DML or SQL inside your PL/SQL.

只需调用 privateProc 就好像它是语言的一部分一样。执行用于在 PL/SQL 中运行 DML 或 SQL。

回答by Margaret

CREATE OR REPLACE PACKAGE BODY testPackage AS

PROCEDURE publicProc; --Forward declaration

PROCEDURE publicProc IS
BEGIN
privateProc; --exec privateProc;
END;

PROCEDURE privateProc IS
BEGIN
DBMS_OUTPUT.PUT_LINE('test');
END;

END testPackage;

//call testPackage.publicProc