plsql - Inside an Oracle 12 "package", how do I make a variable or function or procedure accessible or not accessible? -
i'm former java developer, using oracle's sql-developer create oracle "packages."
oracle's websites indicate it's possible create oracle "package" in objects (variables, functions, procedures) accessible "outside" scope of package, while others accessible "inside" package.
i.e., i'm trying (pseudocode!), intentionally superficially resembles java.
so, i'm asking, "how 1 implement functionality similar (java's) public , private in oracle pl sql package"? ("see 'oracle keyword' enough point me in right direction.)
thanks in advance!
create package // header **public** number nvisibleoutside := 1; **private** number nnotvisibleoutside := 14922016; public procedure pvisibleoutside (); public function fnotvisibleoutside(); /* other stuff */ // body /* actual code of pvisibleoutside , fnotvisibleoutside(); */ end a;
oracle uses package specification , package body. effectively, specification defines of procedures/functions/variables/etc want accessible other areas of code (for example, package). body contains definitions of other procedures , functions "private" , logic behind definitions in package specification.
the example have provided above go follows:
create or replace package xx_example_package -- variable visible code n_visible_outside number := 1; -- procedure visible code procedure p_visible_outside ( ); end xx_package_specification; / create or replace package body xx_example_package -- variable visible whole package body not -- external code v_dummy varchar2(100); -- procedure visible code through specification procedure p_visible_outside -- declaring variable visible procedure n_not_visible_outside number := 14922016; begin -- logic end p_visible_outside; -- function not visible outside not declared in specification -- can accessed code within package function f_not_visible_outside return boolean --logic end f_not_visible_outside; end; /
you call "visible" procedure in way package:
xx_example_package.p_visible_outside;
and, likewise, can call "visible" global variable in way package:
-- use in code say, parameter xx_example_package.n_visible_outside; -- assign value variable in code v_dummy := xx_example_package.n_visible_outside;
as beginner isn't important follow development standards, however, in future should. hopefully, have local development standards however, find oracle pl/sql standards somewhere on google.
Comments
Post a Comment