oracle 如何在包内声明公共和私有项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16130165/
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
How to declare a public and a private item inside a package?
提问by saplingPro
Can anyone please explain me the difference between public items inside the package
and private items inside package
?
任何人都可以请解释我之间的差异public items inside the package
和private items inside package
?
What type of deceleration is this :
这是什么类型的减速:
create or replace package BOOK_MANAGEMENT
as
function OVERDUE_CHARGES(aName IN VARCHAR2) return NUMBER;
procedure NEW_BOOK (aTitle IN VARCHAR2,
aPublisher IN VARCHAR2, aCategoryName IN VARCHAR2);
end BOOK_MANAGEMENT;
回答by cjds
Public and Private Items in a package
包中的公共和私人项目
Public is a keyword denoting that that particular item can be accessed outside the package.
Public 是一个关键字,表示可以在包外访问该特定项目。
Private means that the item will only be used internally in the package.
私有意味着该项目将仅在包内部使用。
Example
例子
create or replace package BOOK_MANAGEMENT
as
function OVERDUE_CHARGES(aName IN VARCHAR2) return NUMBER;
procedure NEW_BOOK (aTitle IN VARCHAR2,
aPublisher IN VARCHAR2, aCategoryName IN VARCHAR2);
end BOOK_MANAGEMENT;
Now the procedure and function here are public and accessible to the outside world.
现在这里的程序和功能是公开的,可以被外界访问。
However now the body for example
但是现在身体例如
CREATE PACKAGE BODY BOOK_MANAGEMENT AS
number_of_books INT; /*<-- visible only in this package*/
/*Rest of body blah blah blah*/
END BOOK_MANAGEMENT;
Note above the number of books is private and isn't shown to the user. It is however (assumed to be) necessary to implement the methods
注意上面的书籍数量是私人的,不会向用户显示。但是(假设是)有必要实现这些方法
Similarly you could have private functions also
同样,您也可以拥有私人功能
How to make number_of_books public
如何公开 number_of_books
create or replace package BOOK_MANAGEMENT
as
number_of_books INT;/*Now its public*/
function OVERDUE_CHARGES(aName IN VARCHAR2) return NUMBER;
procedure NEW_BOOK (aTitle IN VARCHAR2,
aPublisher IN VARCHAR2, aCategoryName IN VARCHAR2);
end BOOK_MANAGEMENT;
回答by LGS
Note - in-line functions in a package cannot be 'private' because their definition must be in the package header to determine their 'purity'. You cannot issue PRAGMA RESTRICT REFERENCES in a package body. I believe this to be a bug (using Oracle 11.2.0.4).
注意 - 包中的内联函数不能是“私有的”,因为它们的定义必须在包头中才能确定它们的“纯度”。您不能在包正文中发出 PRAGMA RESTRICT REFERENCES。我认为这是一个错误(使用 Oracle 11.2.0.4)。