如何在包装内声明公共物品和私人物品? [英] How to declare a public and a private item inside a package?
问题描述
有人可以解释一下public items inside the package
和private items inside package
之间的区别吗?
Can anyone please explain me the difference between public items inside the package
and private items inside package
?
这是什么类型的减速:
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;
推荐答案
包装中的公共物品和私人物品
Public是一个关键字,表示可以在软件包外部访问该特定项目.
Public is a keyword denoting that that particular item can be accessed outside the package.
私有表示该商品将仅在包装中内部使用.
Private means that the item will only be used internally in the package.
示例
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.
但是现在身体为例
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
如何公开数字图书
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;
这篇关于如何在包装内声明公共物品和私人物品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!