Can we create nested package in PL/SQL like we do in Java? I mean can we create a package inside package in Oracle PL/SQL 11g?
Nope:
create or replace package pkg as
package pkg_nested as
var integer;
end;
end;
/
sho err
LINE/COL ERROR
-------- -----------------------------------------------------------------
2/22 PLS-00103: Encountered the symbol "AS" when expecting one of the following:
:= . ( @ % ; not null range default character
5/1 PLS-00103: Encountered the symbol "END"
create or replace package pkg as
var int;
end;
/
sho err
No errors.
create or replace package body pkg as
package pkg_nested as
var integer;
end;
end;
/
sho err
LINE/COL ERROR
-------- -----------------------------------------------------------------
2/22 PLS-00103: Encountered the symbol "AS" when expecting one of the following:
:= . ( @ % ; not null range default character
5/1 PLS-00103: Encountered the symbol "END"
But you can nest procedures and functions within each other:
create or replace procedure p as
procedure p_nest as
procedure p_nest2 as
procedure p_nest3 as
begin
dbms_output.put_line('Nested');
end p_nest3;
begin
p_nest3();
end p_nest2;
begin
p_nest2();
end p_nest;
begin
p_nest();
end p;
/
exec p();
Nested