SqlPlus query issue (Package Spec and Body)

2019-05-03 09:01发布

问题:

I am trying to get package spec and body from sqlplus by doing so..

select text from all_source
where name = 'PACK_JACK'
order by line;

but I am only getting its body not the spec.. what I have to change to get both of them as one file.. Thank you

回答1:

There is a TYPE column in all_source view. The type can have 2 values - 'PACKAGE' and 'PACKAGE BODY'. So to get the spec,

select text from all_source
where name = 'PACK_JACK'
and type = 'PACKAGE'
order by line;

and to get the body

select text from all_source
where name = 'PACK_JACK'
and type = 'PACKAGE BODY'
order by line;

Additionally, instead of using all_source, you can use user_source. all_source includes everything including system packages. USER_SOURCE only has user defined packages.



回答2:

To get the package body, you run:

select text from all_source
where name = 'PACK_JACK'
  and type = 'PACKAGE BODY'
order by line;

As opposed to:

select text from all_source
where name = 'PACK_JACK'
  and type = 'PACKAGE'
order by line;

But chances are you don't have the right to see the package body. So it's hidden from the ALL_SOURCE table.